The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. July 22, 2019, 09:58:23 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Copy to clipboard automatically?  (Read 6771 times)
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« on: April 30, 2011, 09:57:24 PM »

Is it possible to copy arbitrary text to the clipboard, without the user doing anything?

For example, user lands on a page, and I want to automatically copy the URL to their clipboard.
I can get as far as inserting into a hidden field that I add to the page, but, copy doesn't seem to work.

document.execCommand("Copy") should work, but doesn't seem to. Did the browsers all plug this up? Also the flash trick isn't acceptable, since I need it to work on iPad and iPhone.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
Bompa
Administrator
Lifer
*****
Offline Offline

Posts: 564


Where does this show?


View Profile
« Reply #1 on: May 01, 2011, 01:33:17 AM »

http://www.frontpagewebmaster.com/m-185852/tm.htm


http://www.htmlgoodies.com/beyond/javascript/article.php/3458851

http://www.dynamicdrive.com/dynamicindex11/copytext.htm


I dunno, might find some ideas there or maybe you've already read them.

Bompa


Logged

"The most beautiful and profound emotion we can experience is the sensation of the mystical..." - Albert Einstein
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #2 on: May 01, 2011, 10:46:55 AM »

I fought this one for quite a long time, having need for some copied text in a back office procedure for my retail sites. The problems are many, the solutions are fewer all the time.

The first time I did it I was able to use JS to fire a Java applet that did it. Soon it was reworked so that the user HAD to interact to make it happen. Later I used actionscript which worked best of all, but then Adobe shut that vector down - I could not fire the copy even from a button. HAD to be the user selecting Copy.

I'm thinking that the Java applet vector might now be the only way (unless you only need IE) but it was not entirely simple. And of course the user will have to have Java running to make that work.

Love to hear about your travels here. That's one trick that will never go out of style.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #3 on: May 01, 2011, 01:46:15 PM »

it seems NOTHING works in mobile safari. Including the user action of a click, allowing for js clipboard access.
BLOWS.

for everything else, it seems
http://code.google.com/p/zeroclipboard/
is the answer.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
daviator
Expert
****
Offline Offline

Posts: 333


View Profile
« Reply #4 on: May 02, 2011, 01:29:22 PM »

While you probably don't care about what the user thinks for the sites you are working on, I have to point out that, as a user, I'd be very dismayed to have whatever I might have in my clipboard replaced (without my okay) by whatever you want to put there.  I wouldn't visit that site again.  (Then again, I might not have visited that site in the first place.)   ROFLMAO
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #5 on: May 02, 2011, 01:35:57 PM »

And then again, given the particular project, he may not care if you ever visit his site again, seeing how it may have a 30day lifespan before it's banned by Google cleverly replaced by another depository of excellent content.  ROFLMAO
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
daviator
Expert
****
Offline Offline

Posts: 333


View Profile
« Reply #6 on: May 02, 2011, 06:42:42 PM »

Yeah, I was kinda thinking it was that sort of site.  I'm hoping I'm smart enough not to navigate to it to begin with.  ;-)
Logged
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« Reply #7 on: May 02, 2011, 08:00:15 PM »

I think automatic copying to the clipboard is not longer allowed be default.
If I remember correctly, the was some sort of exploit you could do, by automatically copying to the clipboard.
And then you would escape the sandbox.
Logged
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #8 on: May 02, 2011, 08:50:01 PM »

Yeah, I was kinda thinking it was that sort of site.  I'm hoping I'm smart enough not to navigate to it to begin with.  ;-)
I'll check my logs for your ip and let you know if you are  Grin
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!