网站http强制跳转到https的JS代码

2021-02-04    js

方法1

<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>


方法2

<script type="text/javascript">
        var selfUrl = window.location.href;
        if (-1 < selfUrl.indexOf('http://')) {
          selfUrl = selfUrl.replace('http://', 'https://');
          window.location.href = selfUrl;
        }
</script>


标签:

« 没有了! 屏蔽右键、F12等代码 »

赞赏


微信

支付宝
请站长喝杯咖啡吧!您的赞赏将被用于
  • 维护博客的稳定运行
  • 博客空间与域名费用
  • 发布更多文章与教程

评论

发表评论