Questo codice fa il trucco:
JavaScript
<script type="text/javascript">
function focusOnIframe(iFrameID) {
if (frames[iFrameID]!=undefined)
frames[iFrameID].focus(); // Works in all browser, except Firefox
else
document.getElementById(iFrameID).focus(); // Works in Firefox
}
</script>
HTML (ad esempio)
<input type="button" id="setfocus" value="Set focus" onclick="focusOnIframe('myiframe')" />
<p>Bla<br />Bla<br />Bla<br />Bla<br />Bla<br /></p> <!-- Just some filler -->
<iframe id="myiframe" src="yourpage.html"></iframe>
<p>Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br />Bla<br /></p> <!-- Just some filler -->
ho testato in Firefox 3.6.6, Ferro 5.0.380, Opera 10.60, IE 6 e IE 8.
fonte
2010-07-14 02:49:37
Avete il controllo del contenuto nell'iframe? –
sì, e si trova sullo stesso dominio –
IE 6+, FF3 +, Chrome: tutti fanno quello che hai appena detto di default. Faccio clic sull'iframe e premo la freccia verso il basso. L'iframe scorre la pagina no. Cosa vuoi? – galambalazs