Forum Moderators: open

Message Too Old, No Replies

Copy To Clipboard

Is this possible without using a mehtod that gives a browser warning?

         

itledi

4:48 pm on Jan 21, 2008 (gmt 0)

10+ Year Member



I created a input field where once the user clicks inside, the contents becomes highlighted. I'd like to take this one step further, by having the contents being copied to the clipboard.

I'm able to do this, but I get promoted saying the script is trying to access the clipboard in IE7, and I presume other browsers as well.

I imagine that's because there is a possible security risk in being able to copy information the user already has in their clipboard.

Is there a way to rewrite the code where it can only write content to the clipboard without getting that warning prompt from the browser?

Thanks

<input type="text" onfocus="javascript:this.select();field=this.createTextRange();field.execCommand('Copy');" value="copy this" />

eelixduppy

7:18 pm on Jan 21, 2008 (gmt 0)



I believe it's based on the settings of the browser itself that brings the prompt up or not, and in that case, there is nothing you can do about that, the security is there for a reason.

As far as your code is concerned, are you aware that your code only works for IE and not for other browsers such as Mozilla? In case you aren't, if you do a quick google search you'll find some solutions that are a little more cross-browser compatible.