本方法使用的Js Get访问,解析Json
如果已经收录,点击进入百度收录页面
如果未收录,点击进入百度推送页面
$(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);
}
});
});
脚本执行后,将判断提交的地址是否被百度收录,实现逻辑可根据业务进行合理修改即可。
评论