Sunday, May 19, 2024
164
rated 0 times [  170] [ 6]  / answers: 1 / hits: 15956  / 11 Years ago, wed, april 3, 2013, 12:00:00

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?


More From » internet-explorer

 Answers
9

Got the answer, now it works on all browsers



<script>
window.onload = function() {
// blur the iframe
document.getElementById(bing).blur();
// set focus on #foo
document.getElementById(foo).focus();
// when iframe tries to focus, focus #foo
document.getElementById(foo).onblur = function() {
this.focus();
};
};
</script>
<input id=foo type=text value=foo /><br />
<iframe id=bing width=800 height=500 src=http://wwww.bing.com />

[#79143] Tuesday, April 2, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
briza

Total Points: 259
Total Questions: 94
Total Answers: 101

Location: Reunion
Member since Mon, Dec 28, 2020
3 Years ago
;