Code to copy to clipboard
Hi friends
I have some hands on experience in java script now. I have even done some small programs in java script. But I was wondering that I could create a program that copies something to my clipboard. I mean a simple program that copies something to the clipboard on pressing a button. Further I want to echo the value into a hidden form input field. So, my question is how can the value be copied in the clipboard. Any help or advice will be appreciated. Thanks in advance.
Re: Code to copy to clipboard
Hello
I wrote a code something close to what you were saying, I think this can be achieved from the code I have posted below. Just go through it. It may help you. Any more problem do post back.
Code:
function copyToClipboard(s)
{
if( window.clipboardData && clipboardData.setData )
{
clipboardData.setData("Text", s);
}
}
Re: Code to copy to clipboard
Hi
Thanks for your reply and thanks for you code. But unfortunately I must say that the code does not work for me. It is giving an error and I can not even guess what the error is all about. I think there is a problem in this par tof the code.
Code:
if( window.clipboardData && clipboardData.setData )
{
clipboardData.setData("Text", s);
}
Pleas if you check again and post me back a more proper code. Thanks
Re: Code to copy to clipboard
Hi
I will definitely post a code back, but before that it would be great if you post your code in there. so that we can see where exactly is the problem and what is the error in the program. Unfortunately you have not posted the code yet, still you can try writing this statement to your code document.execCommand as follows
Code:
document.execCommand("copy",false,text)
If it works let me know.