本文介绍了拦截JavaScript对DOM的访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想知道如何通过JavaScript拦截DOM访问。有没有可用的工具或白皮书? (否则我需要写一个!)I wanted to know how do I intercept a DOM access by a JavaScript. Are there any tools or whitepapers available on this ? (Else I will need to write one!)拦截背后的想法与Web浏览器的安全模块有关。The idea behind the interception is something to do with a security module for web browsers.谢谢。推荐答案你能做的最好就是 DOM突变事件。有各种事件,例如 DOMNodeInserted , DOMNodeRemoved , DOMAttrModified 等(参见上面链接的DOM事件规范)。有一个名为 DOMSubtreeModified 的普通catch-all事件在任何单个DOM变异后被触发;此事件会冒泡,因此您可以在文档上设置一个侦听器,以通知文档DOM的所有更改。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);最新的浏览器支持这些事件,IE除外(包括版本8) )和Opera,它支持一些偶数,但特别是 DOMSubtreeModified 。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. 这篇关于拦截JavaScript对DOM的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-04 01:54