So - I have a page which contains a textarea and a dynamically created IFrame which displays a PDF using the adobe acrobat plugin.
Initially the textarea is focused.
I want the textarea to be focused, but the IFrame steals focus when the pdf is loaded.
In firefox it is trivial to reset the textarea as the focused element.
I do this by listening to the iframes "load" event and then calling .focus() on the textbox.
M$ IE doesnt fire the onload event for dynamically created Iframes, so to determine when its ready I use the readyState property of the IFrame:
var ieIframeReadyHandler = function() {
if( iframe.readyState=="complete" ) {
textarea.focus();
} else {
setTimeout(ieIframeReadyHandler, 100);
}
}
setTimeout(ieIframeReadyHandler, 100);
Note: I dont listen to the readystatechanged event of the iframe since it doesnt seem to fire for the readyState=="complete" case!!
So what happens when this code executes?..... Well nothing. The Iframe pdf is still focused, however if I check which element has focus using document.activeElement (previously this was IE only, howvever firefox 3 now supports this) I am informed that the textarea DOES have focus!!
What the hell??!?
Any ideas?