1
我正在写一个书签,只是从特定的网页中删除一些内容。
现在的事情是网页有“无休止的滚动”分页,你需要在每次页面加载后再次点击书签。有一个小书签在后台运行,并在页面内容更新
是否可以使用书签捕获网页内容更新?
我正在写一个书签,只是从特定的网页中删除一些内容。
现在的事情是网页有“无休止的滚动”分页,你需要在每次页面加载后再次点击书签。有一个小书签在后台运行,并在页面内容更新
是否可以使用书签捕获网页内容更新?
根据http://en.wikipedia.org/wiki/DOM_events#Common.2FW3C_events DOM突变事件已被弃用,所以似乎没有跨浏览器的方式来捕获页面内容更新上的事件。
phari在新的DOM突变事件API中发布了link,这似乎在所有现代浏览器都支持。从该页面用法示例代码:
// select the target node
var target = document.querySelector('#some-id');
// create an observer instance
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.log(mutation.type);
});
});
// configuration of the observer:
var config = { attributes: true, childList: true, characterData: true };
// pass in the target node, as well as the observer options
observer.observe(target, config);
// later, you can stop observing
observer.disconnect();
如果您需要对旧版浏览器的支持,你可以尝试或许这jquery-observe具有回退旧版本浏览器。或者自己写,就像这里https://stackoverflow.com/a/14570614/4712360
另一种选择是检查网站的源代码,也许你可以在网页内容更新后找到一些事件发生在那里。或者你可以挂钩一些在内容更新后被调用的函数,或者,作为最后的手段,你可以简单地设置间隔函数来检查页面上的任何内容是否已经改变。
https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver – radiaph 2015-03-31 14:53:39