jQuery绑定iframe(最小符号) [英] jquery Bind a iframe (tinymce)

查看:70
本文介绍了jQuery绑定iframe(最小符号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在当前窗口中绑定事件,但是我正在使用创建iframe的TinyMCE,并且我希望能够将键绑定设置到iframe窗口中以捕获Control-S

I can bind eventsin the current window, but I'm using TinyMCE which creates an iframe, and I want to be able to set a keybind to the iframe window to capture a control-S

我有:

$(window.child).keydown(function(e) {
    if(!args) args=[]; // IE barks when args is null
    if(e.keyCode == key.charCodeAt(0) && e.metaKey) {
        callback.apply(this, args);
        return false;
    }
});

但这不起作用.想法?

谢谢

推荐答案

起初,访问iframe的时间是一个问题.

It's at first a problem of timing, when to access the iframe.

如果将其绑定到父文档内的某个位置,则可能是iframe内的文档尚未加载.因此,我建议将其直接分配给iframe的onload-event,以确保它是可访问的.此外,取决于浏览器,如何获得指向文档的指针:

If you bind it somewhere inside the parent document, it may be that the document inside the iframe isn't loaded yet. So I would suggest to assign it directly to the onload-event of the iframe, to be sure that it is accessable. Furthermore it depends on the browser, how you'll get a to pointer the document:

<iframe onload="fx(this)" src="some.html" ></iframe>
<script  type='text/javascript'>
function fx(win)
{ 
  var doc=win.contentDocument||win.contentWindow.document;
  $(doc).keypress(
      function(event)
      {
        alert(event.charCode||event.keyCode);
      });
}
</script>

这篇关于jQuery绑定iframe(最小符号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆