用于检测任何页面更改的 Javascript 代码?(也许通过 AJAX)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4369726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript code to detect any page changes? (maybe via AJAX)
提问by PixelPerfect3
Ok so I'm new to writing javascript, and here's what I'm doing/trying to do.
好的,所以我是编写 javascript 的新手,这就是我正在做/正在做的事情。
When a page loads (window.onload) my javascript code goes through all the forms in a page and attaches a certain "onchange" method to them. This works fine for most websites on the internet, except when a page dynamically updates to load more forms on the page. How do I detect such an event and re-run my function?
当页面加载 (window.onload) 时,我的 javascript 代码会遍历页面中的所有表单并将某个“onchange”方法附加到它们。这适用于 Internet 上的大多数网站,除非页面动态更新以在页面上加载更多表单。如何检测此类事件并重新运行我的函数?
For example:
例如:
The Facebook Newsfeed has a bunch of forms associated with all the different statuses/links posted. My code goes through them and attaches the listener. But if go you all the way down the page automatically updates to reveal more statuses/links/etc. (or you click the "Older Posts" link) - but now my javascript code has not run globally again.
Facebook Newsfeed 有一堆与发布的所有不同状态/链接相关联的表单。我的代码通过它们并附加侦听器。但是如果你一直往下走,页面会自动更新以显示更多状态/链接/等。(或者您单击“旧帖子”链接) - 但现在我的 javascript 代码没有再次全局运行。
Anyway I can do that? Thanks.
反正我能做到吗?谢谢。
EDIT: I am writing a browser extension.
编辑:我正在编写一个浏览器扩展。

