【问题标题】:Catch keydown events iframe捕获 keydown 事件 iframe
【发布时间】:2017-01-20 09:41:14
【问题描述】:

我有一个 iframe,包含在我的页面中。

<iframe  scrolling="no" src="https://xx.com/" ></iframe>

xx.com 不允许跨域(我不记得这个参数到底是怎么调用的,但我无法真正访问 iframe 的内容)

那么我有哪些选择来捕获在这个 iframe 中发生的 keydown 事件?我试过了

`$('iframe').keydown(function(e){console.log(1)});`

但是没用(

【问题讨论】:

    标签: javascript jquery html iframe


    【解决方案1】:

    Add click event to iframe

    Live demo

    $('iframe').load(function(){
      $(this).contents().find("body").on('keydown', function(event) { alert('test'); });
    });
    $('iframe').attr("src","JavaScript:'iframe content'");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-03
      • 1970-01-01
      相关资源
      最近更新 更多