473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Detecting dynamic page changes

Hi all,

I'd like to be able to detect when page content is dynamically changed
by Javascript. I'd like to detect any changes to the content, such as
the addition of new DOM elements and when DOM elements that are hidden
are made visible (or vice versa). I will have no advance knowledge of
the scripts that will be run along with the script I will create.

I've implemented a solution that works reasonably well, but I'm not
sure if there are cases I'm not thinking of where it will fail, or if
there are more efficient means of doing the same thing.

My solution is to simply retrieve and periodically compare the content
of the innerHTML property of the main body tag elemnt.

So, summarized as follows:

function check() {
var bodyContent = document.getElementsByTagName('body')[0];
if(bodyContent != oldBodyContent) {
alert('body changed');
}
setTimeout(check, 500);
}

Is there a better way? What won't this catch?

Thanks,
Jeff

Apr 7 '07 #1
1 2576
Jeff wrote on 07 apr 2007 in comp.lang.javascript:
Hi all,

I'd like to be able to detect when page content is dynamically changed
by Javascript. I'd like to detect any changes to the content, such as
the addition of new DOM elements and when DOM elements that are hidden
are made visible (or vice versa). I will have no advance knowledge of
the scripts that will be run along with the script I will create.

I've implemented a solution that works reasonably well, but I'm not
sure if there are cases I'm not thinking of where it will fail, or if
there are more efficient means of doing the same thing.

My solution is to simply retrieve and periodically compare the content
of the innerHTML property of the main body tag elemnt.

So, summarized as follows:

function check() {
var bodyContent = document.getElementsByTagName('body')[0];
This is only a pointer to the body, the content is seen in innerHTML or a
DOM equivalent.
if(bodyContent != oldBodyContent) {
oldBodyContent is not specified.
alert('body changed');
}
setTimeout(check, 500);
}

Is there a better way? What won't this catch?
everything, meseems, and certainly CSS changes like color or
display:none;

==============================

However, since you are the boss of the scripting, why not alert the
change by the changing code itself?

<span onclick = "this.color = 'blue';alert('color changed');" ....
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 7 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: DylanM | last post by:
I have some checkboxes that are generated from the results of a database search. At the moment, the checkboxes are part of a table making up a form. Users are going through the form, clicking the...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
2
by: Simon Harvey | last post by:
Hi all, Is there any easy way to check a field for calues that have changed on a post back. So the page is sent to the user, the user changes some values and I need to know which ones...
5
by: needin4mation | last post by:
Hi, I have an asp.net 1.1 application that populates data from a database. When the user changes data, they have to hit a button to update the data. The data entry form (same form that is...
3
by: whapts3 | last post by:
I'm putting together a rather dynamic page (AJAX/all-that-mess). So... to go between different sorts of content on the page, I have it set up something like this. <a href="#10"...
5
by: pittendrigh | last post by:
There must be millions of dynamically generated html pages out there now, built by on-the-fly php code (and jsp, perl cgi, asp, etc). Programatic page generation is transparently useful. But...
2
by: Jeff | last post by:
Hi, I'd like to be able to detect changes that have been made to the DOM dynamically using Javascript. My current method is to catch the DOMNodeInserted and DOMNodeRemoved events when possible...
5
by: Gui | last post by:
Hi, I'm working in C# .net 2005 with Ajax. I have a page that loads dynamic user controls depending on the scenario. In those user controls, I create dynamic linkbuttons. The user controls are...
9
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.