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

查看:136
本文介绍了如何在客户端使用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天全站免登陆