如何将事件侦听器添加到iframe

时间:2016-09-09 14:34:56

标签: javascript jquery html css iframe

我正在使用触摸屏和iframe开展特定项目。我在test.html文件中有一个简单的iframe:

  <iframe id="framey" src="http://www.w3schools.com/"></iframe>

我正在尝试添加一个事件监听器,让空格键刷新整个页面(test.html)并监听整个时间,即使在iframe站点中导航也是如此。

这是我的javascript:

 $("#framey").on("keyup",function(e)
        {
            if (e.keyCode == 32){
                 location.reload();
            }  
        })  

目前,它仅在初始点击时执行,但在此之后不会。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

https://www.w3.org/wiki/HTML/Elements/iframe

从此链接了解iframe。属性“sandbox”可能对此特定问题有帮助

相关问题