Location protocol Property - Javascript Browser Object Model

Javascript examples for Browser Object Model:Location

Description

The protocol property sets or gets the protocol of the current URL, including the colon (:).

Set the protocol property with the following Values

ValueType Description
protocol String The protocol of the URL.

Possible values: file: ftp: http: https: mailto: etc..

Return Value

A String, representing the protocol of the current URL, including the colon (:)

The following code shows how to return the protocol of the current URL:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//  w  w  w .j a v a 2s  . c o  m
    var x = location.protocol;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials