开发者

Intercept access to DOM by JavaScript

I wanted to know how do I intercept a DOM access by a Java开发者_如何学CScript. Are there any tools or whitepapers available on this ? (Else I will need to write one!)

The idea behind the interception is something to do with a security module for web browsers.

Thanks.


The best you can do is use DOM mutation events. There are various events such as DOMNodeInserted, DOMNodeRemoved, DOMAttrModified etc (see the DOM events spec, linked to above). There is a general catch-all event called DOMSubtreeModified that is fired after any individual DOM mutation; this event bubbles, so you can set a listener on the document to be notified of all changes to the document's DOM.

document.addEventListener("DOMSubtreeModified", function(evt) {
    console.log("DOM mutation", evt);
}, false);

These events are supported in most recent browsers, with the exception of IE (up to and including version 8) and Opera, which supports some evenbts but notably not DOMSubtreeModified.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜