本文由 发布,转载请注明出处,如有问题请联系我们! 发布时间: 2021-05-07Emlog检测百度收录插件代码文章页ajax查询
加载中前言:
今天在其他博客发现了一个Emlog文章页ajax查询是否被百度收录的代码,现在分享给大家。
通过ajax查询文章页百度收录判断,能优化网页加载白屏时间!
提醒一下这里用的是别人的API接口,如果不喜欢可以自己做一个。
正文:
该接口同样还带有js自动推送功能,可省去已被收录的文章进行反复推送的加载时间。
1、把js到模版js文件中即可,建议放到jquery.min.js这个文件的最后面,添加代码如下所示:
$(function () { $.getJSON('https://api.yum6.cn/baidu/query.php?url='+window.location.href, function(json, textStatus) { if (json.state == 1) { $('#ae_bdcx').html('无陌然已被百度收录!'); $("#ae_bdcx").attr('href','https://www.baidu.com/s?wd='+window.location.href); }else{ $('#ae_bdcx').html('提交收录'); $('#ae_bdcx').css('color','#ff0000'); $('#ae_bdcx').attr('href','http://zhanzhang.baidu.com/sitesubmit/index?sitename='+window.location.href); var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') {bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';} else {bp.src = 'http://push.zhanzhang.baidu.com/push.js';} var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(bp, s); } });});
2、找到并打开echo_log.php文件,并在需要显示的位置添加如下代码即可
<a id="ae_bdcx" rel="external nofollow" target="_blank"></a>
温馨提示:接入CDN的需要清理刷新缓存才可看到效果。