JavaScript » Location » protocol

Syntax:
location.protocol

The protocol property is the string at the beginning of a URL, up to and including the first colon (:), which specifies the method of access to the URL.

protocol is a property of both the Link and the Location objects and is the string at the beginning of a URL, up to and including the first colon (:), which specifies the method of access to the URL. Assuming your current window to be the URL...
 
http://home.newco.com/products/enquiries.htm#local?email=name@otherco.com
 
...you could find out the protocol property as follows:

NOTE:
 
Although the protocol property can be set at any time, it is safer to set the href property to change a location.

Examples

Code:
document.write(location.protocol)
Output:
http:
Explanation:

...you could find out the protocol property as follows: