The protocol
property sets or gets the protocol of the current URL, including the colon (:).
protocol |
Yes | Yes | Yes | Yes | Yes |
Return the protocol property.
var v = location.protocol
Set the protocol property.
location.protocol=protocol
Value | Type | Description |
---|---|---|
protocol | String | The protocol of the URL. Possible values:
|
A String type value representing the protocol of the current URL, including the colon (:).
The following code shows how to Return the protocol of the current URL.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!--from w ww .j a v a2s . c om-->
<script>
function myFunction() {
var x = location.protocol;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: