-3

I want to create a javascript to copy text to clipboard and display an alert coupon copied and when user close it or clicks ok it should visit another website in new page.

basically i am using wordpress's siteorigin pagebuilder widget in which i can only provide the javascripct name as "script.js".

so what I want is when that script runs it takes the button id and copy its text to clipboard and then shows a error message and tells code copied and when user cancels the alert or click ok then it should open a link.

Mohit
  • 11
  • 1
    You need to do some little searches before asking such question, as it has already been posted like 5x times in SO. Check this one for example : http://stackoverflow.com/questions/6300213/copy-selected-text-to-the-clipboard-without-using-flash-must-be-cross-browser – Stranded Kid Sep 18 '15 at 10:44

1 Answers1

0

Currently, almost all browsers have prohibited access to the clipboard by javascript.

So, whatever you try here will fail due to browser restrictions. There are settings modifications which re-grant access to the clipboard, but they are not practicable in an end user scenario.

There are certain solutions around which are either based on a java plugin or a small flash app. The latter is the most stable and useful, can be found here:http://zeroclipboard.org/

Axel Amthor
  • 10,980
  • 1
  • 25
  • 44
  • thank you. ok then is there any script to change button's text and then after 15 sec it shows the alert to go to other site – Mohit Sep 18 '15 at 10:55
  • You may change whatever is in the dom, but you can't copy it to the clipboard of the user. – Axel Amthor Sep 18 '15 at 11:04
  • Sorry but I am beginner about this actually i am using wordpress can you share the script please and also what should i write in onClick="". – Mohit Sep 18 '15 at 11:41