JavaScript : Get url protocol HTTP, HTTPS, FILE or FTP


Posted on : Tue, 28th Apr 15 11:38 am GMT

In order to know the network protocol (HTTP, HTTPS, FTP, SMTP, SSH, FILE e.t.c) of the current page we can make use of the window.location.protocol objet in Javascript,

var urlProtocol = window.location.protocol;

File : pageProtocol.html Language : HTML
<html>
<head>
<title>Get current page Protocol using JavaScript</title>
</head>
<body onload="getCurrentPageProtocol()">

<div id="pageDetails"></div>




<script>
function getCurrentPageProtocol() {
    var currPageURL = window.location.protocol;
    document.getElementById("pageDetails").innerHTML = "<strong>Current Page Protocol : </strong>" + currPageURL;
}
</script>

</body>
</html>


Advertisements






Javascript : Get Page protocol


We are operating with limited resources due to COVID-19 - Stay Safe!


We stands in support of racial equality!

Follow us : Facebook - Twitter