0

When I have the code and test it in my chrome it doesn't work in my local client.

What am I missing?

function copyToClipboard( text ){
                var copyDiv = document.createElement('div');
                copyDiv.contentEditable = true;
                document.body.appendChild(copyDiv);
                copyDiv.innerHTML = text;
                copyDiv.unselectable = "off";
                copyDiv.focus();
                document.execCommand('SelectAll');
                document.execCommand("Copy", false, null);
                document.body.removeChild(copyDiv);
            }
<input type="submit" onclick="copyToClipboard('testtestt')" >

Thanks!

http://www.pakzilla.com/2012/03/20/how-to-copy-to-clipboard-in-chrome-extension/

"https://jsfiddle.net/wz28pp9k/3/"

HelloWorld1
  • 13,688
  • 28
  • 82
  • 145
  • If you don't wrap js code in onload method in jsFiddle, it works: https://jsfiddle.net/wz28pp9k/4/ Next time, debug your code... – A. Wolff Aug 16 '15 at 11:40
  • Load script in `Head` https://jsfiddle.net/wz28pp9k/5/ is working. – Manwal Aug 16 '15 at 11:41
  • it doens't work in my client computer. I also have acticated cognito in chrome but the same problem occur. "jsfiddle.net/wz28pp9k/5" Where can I retrieve the value to display it as a alert message for testing? – HelloWorld1 Aug 16 '15 at 11:47
  • Wolff - It doesn't work in my client computer and I don't understand why – HelloWorld1 Aug 16 '15 at 11:48
  • But how do you debug it??? Error in console? `Where can I retrieve the value to display it as a alert message for testing?` AFAIK this is not possible to get clipboard data outside any onpaste event. But anyway, in your provided example, you already know the data set in clipboard so your question doesn't really make sense. This is more relevant example to test it: https://jsfiddle.net/wz28pp9k/10/ – A. Wolff Aug 16 '15 at 11:52
  • Using Chrome Ctrl F12 and debugging it. I can see the process of the sorucecode but I cannot retrieve the result by pasting the value to display "testtestt". – HelloWorld1 Aug 16 '15 at 11:55
  • How should I wrap up the code inside of the onlead method. Can you show me Wolff? – HelloWorld1 Aug 16 '15 at 11:56
  • I tried but it doesn't work. – HelloWorld1 Aug 16 '15 at 11:58
  • There is many many ways.... e.g: https://jsfiddle.net/bm1o9o38/ Now i'm not sure this is your question because this is really basic example of js behaviour. What exactly are you expecting??? – A. Wolff Aug 16 '15 at 11:59
  • I tried a new approach by connecting to a remote desktop and the sourcecode works perfectly. thank you guys for your help! – HelloWorld1 Aug 16 '15 at 12:00

0 Answers0