How to change focus out of iframe?

2019-08-10 18:46发布

问题:

Got some code which loads an input box, and then below this is an iframe with a textarea... Problem is I want the focus to be on the input box when the page loads, but it always jumps to the textarea because the iframe loads second...

How do I keep focus on the first element in the page?

回答1:

Put this inside the iframe code.

<script language="text/javascript">
window.parent.document.getElementById("idOfInput").focus();
</script>