相关疑难解决方法(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万
查看次数

如果URL中不存在http://如何?

http://如果URL尚未包含协议(例如http://,https://ftp://),我该如何添加?

例:

addhttp("google.com"); // http://google.com
addhttp("www.google.com"); // http://www.google.com
addhttp("google.com"); // http://google.com
addhttp("ftp://google.com"); // ftp://google.com
addhttp("https://google.com"); // https://google.com
addhttp("http://google.com"); // http://google.com
addhttp("rubbish"); // http://rubbish
Run Code Online (Sandbox Code Playgroud)

php regex

107
推荐指数
3
解决办法
10万
查看次数

标签 统计

https ×1

javascript ×1

php ×1

regex ×1

window.location ×1