js强制性http的网站跳转到https
来源:网络
点击数: 次
发布时间:2021年01月04日
问题:使用js强制性http的网站跳转到https
解决:有两种方式
第一种是获取判断如果不是https就强制跳到http
<script type="text/javascript">
var targetProtocol = "https:";
if (window.location.protocol != targetProtocol)
window.location.href = targetProtocol +
window.location.href.substring(window.location.protocol.length);
</script>
第二种,同上,不过支持低版本的浏览器
<script type="text/javascript">
var url=window.location.href;
url=url.replace("http:","https:")
window.location.replace(url);
</script>