[英]How do you detect if the page is a redirect using Javascript in the client side
[英]How can I use JavaScript on the client side to detect if the page was encrypted?
是否可以在客户端检测用户是否使用加密页面?
换句话说 - 我想知道当前页面的URL是以http还是https开头。
使用window.location.protocol
检查它是否为https:
function isSecure()
{
return window.location.protocol == 'https:';
}
或者,如果您没有本地范围的位置,则可以省略指定“窗口”。
function isSecure()
{
return location.protocol == 'https:';
}
谷歌分析师告诉我:
if ("https:" == document.location.protocol) {
/* secure */
} else {
/* unsecure */
}
最新浏览器的第二种方法:
var secure = window.isSecureContext;
或者只是获取isSecureContext:
if (isSecureContext) {
...
}
更多信息: https : //developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts#Feature_detection#Feature_detection
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.