wood burning stoves*
The moose likes Ranch Office and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » This Site » Ranch Office
Bookmark ""copy to clipboard" doesn Watch ""copy to clipboard" doesn New topic
Author

"copy to clipboard" doesn't work

Mike Blaszczak
Greenhorn

Joined: Sep 02, 2013
Posts: 22
The "Copy to clipboard" link on CODE blocks doesn't appear to work in Firefox 23, but works fine in IE 10. When I try to use the feature in FireFox 23, I get a popup saying that "the code is in your clipboard now", but my clipboard is unchanged. Is there some setting I must change in order to have this feature work correctly?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Most browsers actively work to block interaction with the clipboard from JavaScript, and don't provide a setting to allow it. There's a workaround that uses Flash, but lots of users block that these days, too. As you observe, Internet Explorer does not block much of anything.


[Jess in Action][AskingGoodQuestions]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41137
    
  45
You would have to explicitly allow JavaScript to do this, since it's a major security issue. Here's how to do it for Firefox.


Ping & DNS - my free Android networking tools app
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
I usually use the “view plain” link: that opens the code in a sub‑window and you can easily copy or drag and drop thence.
Mike Blaszczak
Greenhorn

Joined: Sep 02, 2013
Posts: 22
What's the security issue?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Replacing the value that a user thinks is in the clipboard (whatever they've cut last) with something else is a vector for social engineering malware attacks. It's a weak one; but one nevertheless.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41137
    
  45
Allowing JavaScript to access the clipboard means that a malicious web site can get at your credit card information - if you happen to access that site right after you had that in your clipboard. Unless you keep track of what you have on clipboard any time you surf the web, I'd suggest it's a good idea to leave that turned off.
Mike Blaszczak
Greenhorn

Joined: Sep 02, 2013
Posts: 22
Ulf Dittmer wrote:Allowing JavaScript to access the clipboard means that a malicious web site can get at your credit card information - if you happen to access that site right after you had that in your clipboard. Unless you keep track of what you have on clipboard any time you surf the web, I'd suggest it's a good idea to leave that turned off.
That seems to be an issue about reading the clipboard; this feature writes to the clipboard.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Did you not read my reply?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41137
    
  45
Mike Blaszczak wrote:That seems to be an issue about reading the clipboard; this feature writes to the clipboard.

Correct. So it depends on how finegrained the security settings are - whether any given browser allows read and write access to be enabled separately.
 
 
subject: "copy to clipboard" doesn't work
 
Similar Threads
copy to clipboard is not working
Happy New Year! Welcome to our new forums!
Need help exporting to clipboard
How to copy a image to clipboard in FIREFOX browser using javascript?
Code tags problem!