Consider you have to write some javascript/jquery which is to be run on a multitude of websites and you need to be informed on updates made to the page's content (reason is not important). For instance, everytime a few new elements are added to the page you need to be informed of these divs and these divs alone.

Also this script cannot be a timeout checking the entire document because that will kill the browser's resources for large pages/a lot of javascript. It needs to sit there and not take up many resources then fire only, and only when the document has been altered. Even if a new node is altered, that node is to then monitor it's own child nodes and fire if any of those newly added nodes change.

I found MutationObservers to fulfill this need for Firefox and Google Chrome. But after days of painstaking research, and trial and error tests, aswell as seeking advice from other professionals - none of us have come up with a non-resource hogging way of doing this for IE.

Any ideas/suggestions/code please suggest

Recommended Answers

All 5 Replies

everytime a few new elements are added to the page

If you are not the one controlling this, you're stuck with what you have for now.

Actually, there is way of doing it as I have seen it done. But just can't implement it.

The only good ways I can see this working is if you control the input method (i.e., data flow that builds the div). Alternatively, if you control the source (the database), you can use whatever method you use to push the data to also keep track of activity, and push a reference to run your script using whatever data model you are using to store/transfer data.

Really, we would need a lot more info about what you are doing, what methods you are using for data aquisition/transfer/storage, and a slew of other goodness...

What do you mean with "doing this for IE"?
Are you implying that you have a working code for other UA's?!

Member Avatar for stbuchok

If you are talking about the pages communicating across multiple users, look at SignalR if you use ASP.Net.

However, if you want observers in just the page, look at using knockout.js or angular.

Also, in the next version of JavaScript, they are implementing observables (not helpful right now but thought I'd mention it anyways.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.