Javascript code to detect any page changes? (maybe via AJAX)

╄→尐↘猪︶ㄣ 提交于 2019-12-04 15:57:34

问题


Ok so I'm new to writing javascript, and here's what I'm doing/trying to do.

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?

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.

Anyway I can do that? Thanks.

EDIT: I am writing a browser extension.


回答1:


use .live() ?

$(document).ready(function()
{
    $(document).live("onchange",function()
    {
        // blah?
    });
});


来源:https://stackoverflow.com/questions/4369726/javascript-code-to-detect-any-page-changes-maybe-via-ajax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!