我过滤百度上一下垃圾信息,当刷新(右键,重新加载)的时候,或新开一个网页,就有效果
但当在百度页面内再次输入文字并按enter搜索的时候,它自己在页面内加载内容,好像没有刷新页面,因此,css或JS无法产生效果。
如果解决这个问题:当网页发生变化的时候,就运行css或js。
如以下简单例子,把百度页面的背景变色:
function addGlobalStyle(css) {
var head,
style;
head = document.getElementsByTagName('head') [0];
if (!head) {
return;
}
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
//背景变色
addGlobalStyle('body { background: rgba(86,255,170,0.8) ! important;}');
你说的网页变化应该是ajax请求后页面更新,可以把要执行的function绑定ajaxcomplete。
具体http://api.jquery.com/ajaxcomplete/