360搜索: 自动收录功能 js 提交代码报错问题

栏目: JavaScript · 发布时间: 7年前

内容简介:360搜索: 自动收录功能 js 提交代码报错问题由于360 自动收录默认的 js 代码使用

360搜索: 自动收录功能 js 提交代码报错问题

360搜索: 自动收录功能 js 提交代码报错问题

由于360 自动收录默认的 js 代码使用 document.write , 所以在 chrome 会直接报错。修改成 document.body.appendChild

<!-- <a href="https://www.miaoroom.com/tag/360" data-toggle="tooltip" title="查看更多关于 360 的文章" target="_blank">360</a> 自动收录 -->
<script>
  (function () {
    var s3 = document.createElement('script');
    s3.id = 'sozz';

    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
      s3.src = 'https://jspassport.ssl.qhimg.com/11.0.1.js?YOUR_KEY';
    } else {
      s3.src = 'http://js.passport.qihucdn.com/11.0.1.js?YOUR_KEY';
    }
    document.body.appendChild(s3);
  })();
</script>

原因参考:避免三方 js 文件被重复加载

事情还没有完,其加载的 js 里是这样一段代码,还是包含了 document.write ...

document.write('<script charset="utf-8" src="https://s.ssl.qhres.com/ssl/ab77b6ea7f3fbf79.js"></script>')

360 的这提交代码真是不行啊。。。

我手动获取了 ab77b6ea7f3fbf79.js 的代码,如下

(function(e){function t(e){var t=location.href,n=t.split("").reverse(),r=e.split(""),i=[];for(var s=0,o=16;s<o;s++)i.push(r[s]+(n[s]||""));return i.join("")}var n=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.so\.com)/gi,r=e.location.href;if(r&&!n.test(r)&&window.navigator.appName){var i="//s.<a href="https://www.miaoroom.com/tag/360" data-toggle="tooltip" title="查看更多关于 360 的文章" target="_blank">360</a>.cn/so/zz.gif",s=document.getElementById("sozz"),o=s.src.split("?")[1],u=t(o),a=new Image;r&&(i+="?url="+encodeURIComponent(r)),o&&(i+="&sid="+o),u&&(i+="&token="+u),o&&(a.src=i)}})(window);

逻辑很简单,就是加载一个 gif 图片,后面缀上当前 URL 和网站标识 (第一端代码里的 YOUR\_KEY)

由于 360 自动收录默认的 js 代码使用 document.write , 所以在 chrome 会直接报错。解决方法

所以,解决方法就是把下面这段代码里的 YOUR\_KEY 替换成自己的,然后贴到网页里就可以了。

<script>
  (function(e){function t(e){var t=location.href,n=t.split("").reverse(),r=e.split(""),i=[];for(var s=0,o=16;s<o;s++)i.push(r[s]+(n[s]||""));return i.join("")}var n=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.so\.com)/gi,r=e.location.href;if(r&&!n.test(r)&&window.navigator.appName){var i="//s.360.cn/so/zz.gif",o="YOUR_KEY",u=t(o),a=new Image;r&&(i+="?url="+encodeURIComponent(r)),o&&(i+="&sid="+o),u&&(i+="&token="+u),o&&(a.src=i)}})(window);
</script>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Cascading Style Sheets 2.0 Programmer's Reference

Cascading Style Sheets 2.0 Programmer's Reference

Eric A. Meyer / McGraw-Hill Osborne Media / 2001-03-20 / USD 19.99

The most authoritative quick reference available for CSS programmers. This handy resource gives you programming essentials at your fingertips, including all the new tags and features in CSS 2.0. You'l......一起来看看 《Cascading Style Sheets 2.0 Programmer's Reference》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

MD5 加密
MD5 加密

MD5 加密工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具