我想知道一個不屬於我的站點上的某些DOM元素的所有更改,因此我可以接收有關DOM元素更改的瀏覽器通知。 如果我無法在網站上編寫代碼,我該如何做到這一點? 我想用這個辦法:我可以在不是我的網站上添加事件監聽器嗎?
// select the target node
var target = document.getElementById('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();
<div id="some-id"></div>
謝謝!
如何將是這個其他網站上運行您的代碼? – vlaz
這是我的問題。 – alwizo
但你還沒有給我們任何工作。你想在某種瀏覽器插件中使用它嗎?你想讓它在每個用戶的機器上運行嗎?你只想要你的嗎?你的問題幾乎等同於「我該怎麼做」 - 是的,它可以得到回答,但需要澄清。 – vlaz