0

My application generates a link from the song that is currently playing. My idea is to set a button with a click event that copy the link to the clipboard.

I've seen solutions like zeroclipboard but flash isn't allowed, so it should be just javascript.

Juan Riaza
  • 1,618
  • 2
  • 16
  • 35
  • Possible duplicate of [How to Copy to Clipboard in JavaScript?](http://stackoverflow.com/questions/400212/how-to-copy-to-clipboard-in-javascript) – Colin Brock Jan 23 '12 at 21:06
  • @Colin it's a special enviroment, I've tried several methods and none of them worked. – Juan Riaza Jan 25 '12 at 17:22
  • This is a thorny problem because you're trying to escape the browser sandbox. Browsers intentionally don't provide clipboard access from JavaScript because it can leak sensitive information to malicious pages. What's possible greatly depends on what browsers you're targeting, what kind of device they'll be running on, and what interaction model you want. Can you explain further exactly what your target environment is? – Sam Hanes Jan 28 '12 at 03:13
  • @SamHanes it's the new [spotify platform](http://developer.spotify.com/en/spotify-apps-api/overview/), based on a branch of chromium. – Juan Riaza Jan 28 '12 at 10:01

3 Answers3

1

From what I can remember, this only works in Flash. I think the best workaround is to put the text in an input box and instruct the user to copy it manually.

mager
  • 4,813
  • 8
  • 29
  • 30
0

Yeah... Don't do that.

Train your users to use drag-and-drop (which works fine for HTML links without any "clever" hacks). They will thank you for it.

If you can't achieve what you want with drag-and-drop, submit a bug against the application you're trying to drag-and-drop into.

alsuren
  • 168
  • 1
  • 2
0

It's not going to work:

>> document.queryCommandEnabled('Copy')
false
Juan Riaza
  • 1,618
  • 2
  • 16
  • 35