Current location - Quotes Website - Team slogan - It is easy to judge whether the current network protocol is http or https with js.
It is easy to judge whether the current network protocol is http or https with js.
There is a location subobject in the document object of JavaScript, which includes the following yes attributes:

Document.location.host // indicates the current domain name+port number.

Document.location.hostname // stands for domain name.

Document.location.href // represents the full URL.

Document.location.port // indicates the port number.

Document.location.protocol // indicates the current network protocol.

Therefore, the current network protocol can be judged by Article 5 above, and the specific judgment is as follows:

[javascript] View Plain Text

var protocol str = document . location . protocol;

if(protocolStr == "http ")

{

console . log(" protocol = "+protocol str ");

}

else if(protocolStr == "https ")

{

console . log(" protocol = "+protocol str ");

}

other

{

Console.log ("other protocols");

}