如何在客户端使用 JavaScript 来检测页面是否已加密? [英] How can I use JavaScript on the client side to detect if the page was encrypted?

查看:18
本文介绍了如何在客户端使用 JavaScript 来检测页面是否已加密?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在客户端检测用户是否在使用加密页面?

Is it possible to detect, on the client side, whether the user is using an encrypted page or not?

换一种方式——我想知道当前页面的 URL 是以 http 还是 https 开头的.

Put another way -- I want to know if the URL of the current page starts with http or https.

推荐答案

使用window.location.protocol检查是否为https:

function isSecure()
{
   return window.location.protocol == 'https:';
}

或者,如果您没有本地范围的位置,您可以省略指定窗口".

Alternatively you can omit specifying "window" if you don't have a locally scoped location.

function isSecure()
{
   return location.protocol == 'https:';
}

这篇关于如何在客户端使用 JavaScript 来检测页面是否已加密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆