dom - Javascript code to detect any page changes? (maybe via AJAX) - Stack Overflow

I'm new to writing Javascript, and here's what I'm doingtrying to do.When a page loads

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?

EDIT: I am writing a browser extension.

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?

EDIT: I am writing a browser extension.

Share Improve this question edited Dec 6, 2021 at 8:35 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Dec 6, 2010 at 18:35 PixelPerfect3PixelPerfect3 1101 gold badge1 silver badge6 bronze badges 3
  • If you're writing a browser extension, you should probably note that fact. If not, then I'm pretty confused about where your script is used. – Pointy Commented Dec 6, 2010 at 18:43
  • Ah yes sorry...I am writing a browser extension. – PixelPerfect3 Commented Dec 6, 2010 at 18:44
  • Not quite sure what you are trying to do. For detecting mutation events, jQuery mutation events discussion. Doesn’t look straightforward. – Benji XVI Commented Dec 6, 2010 at 18:48
Add a ment  | 

1 Answer 1

Reset to default 3

use .live() ?

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742300101a4417874.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信