<body style="margin: 0px; padding: 0px">
Then I run the following in order to access the markup in the iframe's
which fails for Internet Explorer 6-10 because
document object of the iframe exists, but appears to have no readable properties. Other browsers simply display the string
But interestingly, the following works in IE 6-10, and all other browsers:
To my knowledge
setTimeout executes the passed function in the global scope. So I tried using call but it does not work:
I have seen similar cases where wrapping code in a setTimeout resolves IE iframe difficulties. What is the mechanism or logic behind this in IE? Is there a proper workaround?
Above tests were run in standards mode, with no other errors than those stated.
What is the mechanism or logic behind this in IE? Is there a proper workaround?
The mechanism is very simple: wait one milisecond (four; actually), then attempt to access the iFrame.
Timing is everything. If you call too soon, you will see an empty iFrame. Even if the
If you access the iFrame just after it is encountered in the DOM: most likely it will be empty. It has not been fetched from the Internet yet. Even if the
document.body element may already exist at this point - even if it's going to be empty.
The intended workflow is that you wait for the iFrame
load event. You can safely attach it just after you create the iFrame or set its
src. Finding a cross-browser set of events that messages this reliably is a tricky issue, but
load should work cross-browser.
load event fails to be late enough, wait an extra millisecond. This should not be neccessary, but there might be a stupid bug in IE (I don't think there is).
It you are firing it from the console, this should be successful. Indeed, this has always been the case according to my observation.