相关疑难解决方法(0)

检测HTTP或HTTPS,然后在JavaScript中强制使用HTTPS

有没有办法检测HTTP或HTTPS,然后强制使用HTTPS与JavaScript?

我有一些代码用于检测HTTP或HTTPS,但我不能强制它使用https:.

我正在使用window.location.protocol属性来设置站点的任何内容,https:然后刷新页面以希望重新加载加载到浏览器中的新https'ed URL.

if (window.location.protocol != "https:") {
   window.location.protocol = "https:";
   window.location.reload();
}
Run Code Online (Sandbox Code Playgroud)

javascript https window.location

278
推荐指数
7
解决办法
23万
查看次数

从 http:// 重定向到 https://

我想将用户从我的 http 网站重定向到 https 网站,是否有像元或 JavaScript 或 html 这样的网站来执行此操作,我的网站有一个 http 服务器以及一个安全版本。

html javascript security redirect web

-1
推荐指数
1
解决办法
6252
查看次数

标签 统计

javascript ×2

html ×1

https ×1

redirect ×1

security ×1

web ×1

window.location ×1