计科知识库
  • 源界面
  • 博客圈
  • 专题
  • 博友
  • 登录
  • 注册
源界面 源界面 1个月前

js代码 如果访问的不是指定域名则网页内容为空白

js
  1. <script>
  2. if(document.domain.indexOf('csroad.cn')==-1&&document.domain.indexOf('csroad')==-1&&document.domain.indexOf('kan')==-1&&document.domain.indexOf('wzb')==-1&&document.domain.indexOf('ucvip')==-1){document.body.innerHTML="&nbsp;";document.head.innerHTML="&nbsp;";}
  3. var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
  4. if(location.host.indexOf('csroad.cn')!=-1){
  5. document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%71fb6d2c024dcc4d8709c54a757fec7f' type='text/javascript'%3E%3C/script%3E"));
  6. }
  7. if(location.host.indexOf('kan.pub')!=-1){
  8. document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%71fb6d2c024dcc4d8709c54a757fec7f' type='text/javascript'%3E%3C/script%3E"));
  9. }
  10. if(location.host.indexOf('wzb.pub')!=-1){
  11. document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/hm.js%71fb6d2c024dcc4d8709c54a757fec7f' type='text/javascript'%3E%3C/script%3E"));
  12. }
  13. if(location.host.indexOf('ucvip.cn')!=-1){
  14. document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/hm.js%71fb6d2c024dcc4d8709c54a757fec7f' type='text/javascript'%3E%3C/script%3E"));
  15. }
  16. </script>

这个实现的效果大家可以copy下来进行尝试。
baidu统计代码

  1. <script>
  2. var _hmt = _hmt || [];
  3. (function() {
  4. var hm = document.createElement("script");
  5. hm.src = "https://hm.baidu.com/hm.js?71fb6d2c024dcc4d8709c54a757fec7f";
  6. var s = document.getElementsByTagName("script")[0];
  7. s.parentNode.insertBefore(hm, s);
  8. })();
  9. </script>
  • © 2025 源界面 源码为笔,博客为路,写就数字未来
  • 建议
  • 图片压缩
  • | 鄂ICP备14016484号-6

    鄂公网安备 42068402000140