0

I'm trying to develop a custom coupon system, and all works with IE, but when I try to use the following code on firefox or safari on click it open link and display alert but doesn't copy text:

<script type="text/javascript">
function copy_to_clipboard(text)  
  {  

      if(window.clipboardData)  
      {  
        window.clipboardData.setData('text',text);  
      }  
      else  
      {  



      }  
      alert('<?php echo get_option('custom_message'); ?> Powered by: WpCode.net Couponica');  
      return false;  
  }
</script>

And on the link:

<a onclick="copy_to_clipboard('code to copy')" href="link to open" style="margin-left:40px;" target="_blank">

What's wrong? How can I change this to make it work on firefox?

Nightfirecat
  • 11,432
  • 6
  • 35
  • 51
Pigi
  • 74
  • 8

3 Answers3

1

Clipboard access is not available in Firefox. Take a look at http://code.google.com/p/zeroclipboard/ for a Flash based alternative.

pradeek
  • 21,445
  • 2
  • 31
  • 32
1

It is not possible to copy to clipboard in other browser then IE due security issues. You can use Flash for it, but from Flash 10.0 the security has increased aswell, so only users with Flash 9 or lower are able to copy.

What you can do is when you want someone to copy something, show a popup with a textbox with only the text the need to copy.

Niels
  • 48,601
  • 4
  • 62
  • 81
  • and what about the retailmenot system? that site work well with firefox and safari too...? – Pigi Nov 15 '11 at 09:16
  • The button that copies the text to your clipboard is a Flash application. I forgot to mention that if you got Flash 10 or higher you are able to copy to clipboard, but only if you click on the Flash object itselve it will work. – Niels Nov 15 '11 at 09:20
0

function copyLink(){
                    var link = window.location.href;
                   navigator.clipboard.writeText(link);
                   alert('link copy to clipboard');
                  }
<button class="btn btn-primary" onclick="copyLink()" >Share</button>