Make sure iframe is selected right away

我们两清 提交于 2020-01-25 03:24:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!