jQuery的ZeroClipboard或Zclip没有在剪贴板中的IE 8和7剪贴板、ZeroClipboard、jQuery、IE

2023-09-10 17:31:10 作者:刻薄過客

我使用jQuery插件ZClip或ZeroClipboard通过一个按钮或链接,内容复制到剪贴板。要复制的数据和链接/按钮来激活这个是用ajax哪些需要使用的插件,我重视的元素后,他们已经加载,所以装:

I'm using Jquery plugin ZClip or ZeroClipboard which copies content to the clipboard via a button or link. The data to copy and links/buttons to activate this are loaded using ajax which needs to use plugin, I attach the elements after they have loaded as so:

$('#ajaxbutton').live('click', function() {
   $.ajax({
    type: "POST",
    url: "ajax.php",
    success: function(msg){
      $('a.ajaxcopymulti').zclip({
         path:'js/ZeroClipboard.swf',
         copy:function(){
         return $('p#ajaxdescription').text();
      }
    });
  });
});

和在ajax.php例如:

and in ajax.php for example:

<p id="ajaxdescription">Ajax description copied to clipboard</p>
<p><a href="#" id="ajaxcopy">Click here to copy the above text</a></p>

适用于所有其他的浏览器,但IE 7和IE 8我得到这个错误:

Works for all other browsers but IE 7 and IE 8. I get this error:

Unknown Runtime Error: ZeroClipboard.js, line 135 character 3

因此​​,在插件code更改:

So in the plugin code I change:

this.div.innerHTML = this.getHTML(box.width, box.height);

$(this.div).html( this.getHTML( box.width, box.height ) ); 

这摆脱了运行时错误的,但没有出现被复制到剪贴板中的IE 7和8是任何人都与此非常熟悉给予一些帮助?谢谢你。

Which gets rid of the runtime error, but nothing appears to be copied into the clipboard for IE 7 and 8. Is anyone familiar enough with this to give some help? Thanks.

推荐答案

好吧,我发现了什么错在我的情况。因为这可能是相同的问题,因为你expierience

Ok, I found what's going wrong in my case. probably it will be the same problem as you expierience.

IE浏览器在该行给出了一个错误

IE gives an error at this line

this.div.innerHTML = this.getHTML(box.width, box.height);

下一行是

appendElem.appendChild(this.div);

在这里我们追加this.div的元素appendElem。 appendElem是一个DOM对象,并从放置你的HTML副本域在HTML $ C $,c取决于。为precise它是第二级的父。错误被抛出时,appendElem不能包含this.div作为子节点。在我的情况下我的副本领域,其中表格单元格中。该appendELem在这种情况下,行对象这显然不能包含任何的div(Firefox是足够聪明的清理code)。我裹着我额外的div copyfields将因此appendElem是一个DIV对象。要知道你的appendElem是只包含添加和报警功能,这样的对象是什么:

here we append this.div to the element "appendElem". appendElem is an DOM object and depends from where you placed your html copy fields in your html code. to be precise it is the second level parent. the error is thrown when appendElem can't contain this.div as a child node. In my case my copy fields where in table cells. the appendELem is in this case a Row Object which obviously can not contain any divs (firefox is smart enough to clean up the code). I wrapped my copyfields in extra divs so appendElem will be a DIV object. to know what object your appendElem is containing just add and alert function, like this:

    alert(appendElem);
    appendElem.appendChild(this.div);

希望这有助于!

hope this helps!

卡斯帕Taeymans

Kasper Taeymans