百度站长平台链接提交-js代码推送进化版

百度站长工具链接提交js代码推送进化版,听说优化了加载速度和其它问题,和原提交代码相比变长支持https://网站等,原文来自百度站长学院。

使用方法和原来的代码一样,复制下面的代码放到你喜欢放的地方当然要能用才行。

  1. <script>
  2. (function(){
  3. var canonicalURL, curProtocol;
  4. //Get the <link> tag
  5. var x=document.getElementsByTagName(“link”);
  6. //Find the last canonical URL
  7. if(x.length > 0){
  8. for (i=0;i<x.length;i++){
  9. if(x[i].rel.toLowerCase() == ‘canonical’ && x[i].href){
  10. canonicalURL=x[i].href;
  11. }
  12. }
  13. }
  14. //Get protocol
  15. if (!canonicalURL){
  16. curProtocol = window.location.protocol.split(‘:’)[0];
  17. }
  18. else{
  19. curProtocol = canonicalURL.split(‘:’)[0];
  20. }
  21. //Get current URL if the canonical URL does not exist
  22. if (!canonicalURL) canonicalURL = window.location.href;
  23. //Assign script content. Replace current URL with the canonical URL
  24. !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === ‘https’)?“https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif”:“//api.share.baidu.com/s.gif”;t?(n+=“?r=”+encodeURIComponent(document.referrer),r&&(n+=“&l=”+r)):r&&(n+=“?l=”+r);var i=new Image;i.src=n}}(window);})();
  25. </script>

原创文章,作者:陌涛,如若转载,请注明出处:https://imotao.com/238.html

(0)
陌涛的头像陌涛
上一篇 2019年1月24日
下一篇 2019年1月24日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据