Javascript代码检测任何页面更改? (也许通过AJAX) [英] Javascript code to detect any page changes? (maybe via AJAX)

查看:145
本文介绍了Javascript代码检测任何页面更改? (也许通过AJAX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我是新手写的javascript,这是我在做什么/试图做。

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

当一个页面加载(window.onload)我的JavaScript代码遍历一个页面中的所有表单,并附加一些onchange方法。这对互联网上的大多数网站都能正常工作,除非页面动态更新以在页面上加载更多表单。如何检测这样的事件并重新运行我的功能?

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?

例如:

Facebook新闻源有一堆表单与所有不同的状态/链接相关联。我的代码遍历它们并附加听者。但如果你一路下来,页面会自动更新,以显示更多的状态/链接等。 (或者您点击旧帖链接) - 但现在我的JavaScript代码还没有在全球运行。

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.

编辑:我正在编写浏览器扩展名。

I am writing a browser extension.

推荐答案

使用 .live()

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

这篇关于Javascript代码检测任何页面更改? (也许通过AJAX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆