Some websites have focus
set on an element on window load. If I iframe that website, It seems not able to set focus on parent window, programmatically. This only happens to IE
(9) and Firefox
(19), Opera/Safari/Chrome are fine.
<script>
window.onload = function() {
setTimeout(function() {
// this does not focus #foo
document.getElementById("foo").focus();
// or more seconds that enough to see the iframe focus
}, 3000);
};
</script>
<input id="foo" type="text" value="foo" /><br />
<iframe width="800" height="500" src="http://www.bing.com" />
Does anyone know a workaround for this problem?
Got the answer, now it works on all browsers
If I've read this correctly you just need to prevent the focus being shifted from the parent window to an element in the iframe.
I would use an 'onfocus' trigger on the iframe element to switch the focus back to your page, like so:
If (as I suspect you do) you only want to prevent the iframe stealing the initial focus onload but would like the user to be able to shift focus to it later, use a status variable, like so:
I hope this helps and I'm here if you have any questions.