将事件添加到iframe正文 [英] Add event to iframe body

查看:116
本文介绍了将事件添加到iframe正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为jQuery设置一个自己制作的wysiwyg插件。他几乎已经完成了,但我知道我想将一个keyup事件添加到设计模式的iframe上。但我不能让它奏效。我尝试了几乎所有在互联网上找到的东西。带有designmode的所见即所得iframe的类是.dhwysiwyg。我虽然下一个代码可以工作:

I am setting up a own made wysiwyg plugin for jQuery. He is almost finished but know i want to add a keyup event to a iframe with designmode on. But i can't get it worked. I tryied almost everything a found on the internet. The class of the wysiwyg iframe with designmode is .dhwysiwyg. I though the next code will work:

$(function () {
$('.dhwysiwyg', container).keyup(function () {
// the script
});
});

但这不起作用。 keyup事件不存在。

But this won't work. The keyup event don't exists.

有人可以帮助我吗?

Tom

推荐答案

iframe中的页面是否加载了自己的jQuery副本?如果是这样,请在外部页面(包含iframe的页面,而不是> iframe中的页面)中尝试此操作:

Does the page in your iframe load its own copy of jQuery? If so, try this in your outer page (the page with the iframe in it, not the page in the iframe):

$(function() {
  var frameWindow = $('.dhwysiwyg').get(0).contentWindow;
  frameWindow.$('body').keyup(function() {
    // handler
  });
});

这篇关于将事件添加到iframe正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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