Is there a way I can have a user click a link on my site and have it copy to there clipboard. I saw examples using execCommand("Copy"), but that was to copy textareas. These urls would be dynamically generated. Or is there a way to have it so when they click a url (which would normally open in a new tab), the browser prevents it from opening the new tab and copies the url instead?
Copy href onClick
Started by rsnider19, Nov 15 2010 10:44 AM
1 reply to this topic
#1
Posted 15 November 2010 - 10:44 AM
|
|
|
#2
Posted 15 November 2010 - 04:02 PM
You could use return false to stop browser execute the default behavior or using # as anchor href. This is very simple example to suppress anchor default behavior. Clipboard copying is one of ultimate problem for the century :D, and code here is only work for IE.
<script type="text/javascript">
function copy_to_clipboard(element)
{
if( window.clipboardData && clipboardData.setData )
{
clipboardData.setData("Text", element.innerHTML);
}
return false;
}
</script>
<a href="http://forum.codecall.net" onclick="return copy_to_clipboard(this)">CodeCall Forum</a>
or
<a href="#" onclick="copy_to_clipboard(this)">Copy to clipboard</a>
Edited by nomaden, 15 November 2010 - 04:04 PM.
typo


Sign In
Create Account


Back to top









