Return the protocol of the current URL:
var x = location.protocol;
Click the button to return the protocol portion of the current URL.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {// w w w .j a v a 2 s . co m var x = location.protocol; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The protocol property sets or gets the protocol of the current URL, including the colon (:).
The protocol is a standard that specifies how data are transmitted between computers.
Property Values
Value | Type | Description |
---|---|---|
protocol | String | The protocol of the URL. |
Possible values: file: ftp: http: https: mailto: etc..