Hi all. I have a tricky DOM/IE problem. Currently using IE8 on Windows 7.
There's an HTML page 'P' containing a table 'T', then other elements.
The rows and columns of 'T' are emitted very slowly (say one per second) until the table is finished (ie. </TABLE> tag emitted).
I want to load 'P', then parse the content of 'T', through code.
To that end, I need to wait for 'T' to finish loading all its content. The elements after 'T' take extra time to load, so I don't want to wait for those - I only want to wait for 'T'.
In order to do that, I need to write a function that takes a reference to 'T', and returns TRUE if 'T' has finished loading all its content, FALSE otherwise. (Then I can loop until that function is TRUE.)
The problem is, in IE specifically, how can you determine whether 'T' has finished loading its content or not?
(1) The obvious approach, ie. testing for T.READYSTATE = "complete", does not work. In IE, READYSTATE only works when loading content from external sources. So for a normal table, READYSTATE is "complete" as soon as the table node appears in the DOM - well before its content has loaded.
(2) Testing for RIGHT(T.OUTERHTML,7) = "</HTML>" works fine - but is too ugly for me.
(3) The number of rows is unpredictable, so I can't just wait for that number of rows. And there's nothing special about the last row (to help identify that row through code).
(4) The page isn't mine, so I can't modify the original HTML source at all. Eg. I can't add an ONLOAD event to the table element definition. Of course I can add events to the table at runtime via the DOM - but by then it's too late!
The best method I have found so far, is to assume the table has finished loading if (a) it has any following sibling element(s), ie. T.NEXTSIBLING is not null, or (b) the whole document has finished loading. (b) is to handle the case where 'T' is the very last element in the document (so 'T' will never have a next sibling). Clearly (b) is undesirable, but I can't see a better way to handle that case.
So, does anyone have a better way to determine whether a given table has actally finished loading its content?
Sorry, but how does that help? Page 'P' isn't under my control (per point (4) of my post). I can't modify its source in any way. I've loaded that page through IE automation code. I now have to access the page elements via the DOM.
The problem is, how to tell if the TABLE element has actually finished loading its content in the scenario that I've described?
This topic is now closed. New replies are no longer allowed.