js获取网页请求类型是http还是https

代码如下,即可判断

 1 var ishttps = 'https:' == document.location.protocol ? true : false;
 2 
 3 if(ishttps) {
 4 
 5     alert("这是一个https请求");
 6 
 7 } else {
 8 
 9     alert("http");
10 
11 }

原文链接为w3c中

原文地址:https://www.cnblogs.com/spirit-ling/p/6877975.html