Hi,
Directly copying to the clipboard via JavaScript is not permitted by any modern browser for security reasons. The most common workaround is to use a Flash capability for copying to the clipboard that can only be triggered by a direct user click.
As mentioned already, ZeroClipboard is a popular set of code for managing the Flash object to do the copy. I've used it. If Flash is installed on the browsing device (which rules out mobile or tablet), it works.
The next most common work-around is to just place the clipboard-bound text into an input field, move the focus to that field and advise the user to press Ctrl + C to copy the text.
Other discussions of the issue and possible work-arounds can be found in these prior Stack Overflow posts:
or you can use below plugin
http://plugins.jquery.com/project/copy
$("#elmID").copy()
Here I have created sample that requires latest version of browsers,also need to allow access copy to clipboard
- IE10+ (although this document indicates some support was there from IE5.5+).
- Google Chrome 43+ (~April 2015)
- Mozilla Firefox 41+ (shipping ~September 2015)
- Opera 29+ (based on Chromium 42, ~April 2015)
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div>
<script language="JavaScript">
function CopyToClipboard() {
var text = document.createElement("textarea");
text.innerHTML = window.location.href;
Copied = text.createTextRange();
Copied.execCommand("Copy");
}
</script>
<input type="button" value="Copy Url" onclick="CopyToClipboard();" />
<br />
<br />
Paste Here :
<textarea rows="3" cols="30"></textarea>
</div>
</body>
</html>
Demo
I hope this will help you out.