admin管理员组

文章数量:1310306

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

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>

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

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

So in the plugin code I change:

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

to:

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

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.

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

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>

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

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

So in the plugin code I change:

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

to:

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

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.

Share Improve this question edited Jul 13, 2011 at 16:35 lemon asked Jul 13, 2011 at 16:21 lemonlemon 6051 gold badge8 silver badges21 bronze badges 4
  • 1 Found a work around in the end, I just told it to use window.clipboardData.setData('Text',text); for IE 7 and 8 otherwise use zclip – lemon Commented Jul 14, 2011 at 14:26
  • Melon, can you explain how you did this? I don't understand your solution. I'm using ZeroClipboard with Datatables and TableTools, and have the exact same problem. It all works fine in FF but IE gives me the same problem you documented. I also found that wrapping the jQuery selector around the offending line as you show results in another error when closing the page. – user947303 Commented Sep 15, 2011 at 16:59
  • 1 I check to see if the user is using IE, if not I will load Zclip. If they are using IE I won't load Zclip and will use the function I created that contains window.clipboardData.setData('Text',text); where text is the parameter that contains the string you want to copy. Hope that helps. – lemon Commented Sep 16, 2011 at 14:33
  • Just make sure the adobe flash plugin is installed. – ASKN Commented Sep 26, 2013 at 8:32
Add a ment  | 

3 Answers 3

Reset to default 4

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

IE gives an error at this line

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

next line is

appendElem.appendChild(this.div);

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!

Kasper Taeymans

Also do make sure that your Browser is updated with Flash Plugin for it to work correctly.

I just met this problem, and has solved it. This is because of the improper html tag, the jquery plug-in will add a flash layer with the div, so make sure the html tag outermost layer is div, that is ok.

本文标签: javascriptJquery ZeroClipboard or Zclip nothing in clipboard IE 8 and 7Stack Overflow