簡體   English   中英

如何在客戶端使用JavaScript來檢測頁面是否已加密?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM