开发者

Add event to iframe body

I am setting up a own m开发者_如何学运维ade 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
});
});

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

Can someone help me?

Tom


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
  });
});


I'm not sure about the particulars of your example, but I know that pushing events to an iFrame will sometimes violate the security policy of your browser.


I've never heard of this "design mode" thing (only contentEditable) but your problem might be a security limitation. What are the iframe contents, and are they on the same domain?


this method work for me

$(function() {
      var frameWindow = $('.dhwysiwyg').get(0).contentWindow;
      $(frameWindow.document).delegate("body",'keyup',function() {
      var bodycontent=$(frameWindow.document.body).text();
    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜