2010-06-25 118 views
0

因此,我正在编写一个所见即所得的编辑器,其中包含已经设置好的语法等。我的任务是为跨程序添加复制和粘贴功能。我的代码可以在Ubuntu的谷歌浏览器,Ubuntu和Windows的Firefox浏览器中运行,但不能在Windows浏览器中运行。jquery:Windows谷歌浏览器不会在iframe中触发事件

我已经找到了一些基本的问题。当发送粘贴命令(通过Ctrl + V)事件时,我立即将焦点转换为隐藏的,可控的iframe,并在那里触发事件。然后等待它冒泡,然后处理解析和粘贴。

this.pasteOperation = function(event, controller) { 
    this._cutpastearea.getEditable().focus().trigger(event); 
    setTimeout(function() { controller.clipboardControl().handlePaste(); }, 1); 
}, 

(其中getEditable得到iframe的CONTENTEDITABLE部分)

现在,如果我透露了iframe,并禁用设置超时,我发现焦点已经抓住了,但什么也没有粘贴。如果我继续手动粘贴,然后调用该函数,一切正常。

那么,为什么这不会触发事件?

编辑:提出了问题在Chromium Issues以及。这似乎只是一个iframe问题。

回答

1

找到了解决办法。请致电:

$.fn.forwardEvent = function(event) { 
    this.each(function() { 
     if (this.dispatchEvent) { 
      if (event.originalEvent) { 
       event = event.originalEvent 
      } 
      try { 
       this.dispatchEvent(event); 
      } catch(error) { 
       $(this).trigger(event); 
      } 
     } 
     else { 
      $(this).trigger(event); 
     } 
    }); 
    return this; 
}; 
相关问题