问题
This is possibly a stupid question, but when I'm using an iframe, particular aspects (controlled by event listeners in the html file that is used by the iframe) are available if you click on the frame. If you click outside of the iframe it looses access to those controls and event listeners. Is there a way to make an iframe be already clicked?. Sorry about the bad wording, but I haven't found a single way to do this, any thoughts?
回答1:
try:
iframe.onblur = function() {
iframe.focus();
}
回答2:
<iframe id="iframe" autofocus="true" src="page.html"></iframe>
<script>
document.getElementById('iframe').focus();
</script>
The autofocus attribute in HTML5 can also force an element's focus. In this example, it's redundant.
来源:https://stackoverflow.com/questions/8751734/make-sure-iframe-is-selected-right-away