document ready firing early when unloading
Hello all,
I've run into a rather peculiar issue which I was hoping someone might be able to shed some light on. If I have a large document which takes a while to load, but has links in it - the browser will display some links before the document is 'ready'. That's fine, and I can click on these links, which I do, but this fires the $(document).ready function! Surely this shouldn't happen since the page is being unloaded at this point.
The reason why this is a problem for me, is that in my ready function, I do a check for how many DOM elements are in a table, and give an alert if the incorrect number are found (columns * rows). If I click on the link, there will most likely be an 'odd' number of cells, since the document hasn't finished loaded, and thus an alert shows up.
Here is an example of this in action:
http://sprymedia.co.uk/media/misc/webkit/document_ready.php . The page has a sleep(5) at the bottom of it, so click the link within 5 seconds to see the alert show up before the document has loaded. This occurs in Safari, Firefox and Chrome (not tested on IE).
Is this expected behaviour? Can I test to see if the document actually has loaded or not inside the ready function, so I can decide to display the alert or not?
Many thanks,
Allan