One-click select and copy to clipboard javascript?
September 22, 2007 11:30 AM   Subscribe

What is the javascript used to make a one click "select and copy to clipboard" action like I see they have on photobucket?

Under each image in my gallery on photobucket are four choices of links back to my image. html, embed video etc. When I click in a box a javascript instantly selects the entire link and copies it to my clipboard.

I'd like to use this at my office to speed up some routine work I have to do every morning. (Making links to breaking news stories.)

I think it's javascript but I don't know enough to find it in the source.

I have a javascript like this (found at dynamic drive) but it doesn't work in firefox. The photobucket script works crossbrowser.

I don't want to steal this if the photobucket progammer wrote it and doesn't want to distribute it. But is something like this free on the Internet? (I've searched and searched)
posted by cda to Computers & Internet (4 answers total) 1 user marked this as a favorite
 
I've looked through the source - Photobucket does it via Flash, I'm fairly certain. Firefox won't let websites access the clipboard as it's considered insecure. The JS file is here, if you want to look for yourself.

If you want to implement something like this, try Googling "flashcopier".
posted by wsp at 11:53 AM on September 22, 2007


flash does allow you to write to the user's keyboard, although not read from it.

dont remember the AS offhand, but it's something simple like

Clipboard.write(string)
posted by drjimmy11 at 12:20 PM on September 22, 2007


This is something you typically aren't allowed to do, however, Internet Explorer doesn't mind.

The script for Internet Explorer looks like the following:

window.clipboardData.setData('Text', yourNewClipboardData)

Heres some code that copies the url of a link to the clipboard, for every link on the page.

window.onload = function() {
var links = document.getElementsByTagName("a");
for (var i = 0, j = links.length; i<j; i++) {
links[i].onclick = function() {
window.clipboardData.setData('Text',event.srcElement.href);
event.returnValue = false;
};
}
}

Now, it sounds to me like you want to do this on arbitrary pages that you happen to visit in your browser. If that's the case, copy and enter this (all in one line) into the address bar of IE when you're on the page.

javascript:alert(eval("var l = document.getElementsByTagName('a');for (var i = 0, j = l.length; i<j; i++) {l[i].onclick = function() { window.clipboardData.setData('Text',event.srcElement.href); event.returnValue = false; };}"))
posted by cheerleaders_to_your_funeral at 1:40 PM on September 22, 2007


Response by poster: This what I am trying to make: a form that generates a url.

By Googling flashcopier I found a flashcopier file and uploaded it to my website. It works great!

Now I can't figure out how to get the flashcopier to copy the generated text in form #1.

Maybe it comes down to having two actions in one onclick?

The two seperate forms work in the link above but if anyone can tell me how to combine the two I would appreciate it.

I've tried to get them to work together and failed so I left the two separate forms (since they are working) as they are in the link above if you want to see what I'm talking about.
posted by cda at 4:09 PM on September 22, 2007


« Older Do I maintain non-owner auto insurance or just...   |   Where have all the web emulators gone? Newer »
This thread is closed to new comments.