This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Copy-to-clipboard  RSS feed

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a textbox and a button.
When I click on the button I want to copy the textbox value so that I can paste it to anywhere.

Can anyone tell me how to do that using javascript?

Thanks
 
Gold Digger
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IE

FF + here
 
Zoram Paul
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although Valentin Crettaz, your code supports only Internet Explorer and Not FireFox........

Here is a better solution and its working for any browser:

<script>
function cSn(sn, el)
{
if (window.clipboardData) {
window.clipboardData.setData("Text",sn);
} else {
var flashcopier = 'flashcopier';
if(!document.getElementById(flashcopier)) {
var divholder = document.createElement('div');
divholder.id = flashcopier;
document.body.appendChild(divholder);
}
document.getElementById(flashcopier).innerHTML = '';
var divinfo = '<embed src="snippetty.swf" FlashVars="clipboard='+escape(sn)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
document.getElementById(flashcopier).innerHTML = divinfo;
}
}

</script>





[ UD: removed gratuitous graemlins ]
[ September 28, 2007: Message edited by: Ulf Dittmer ]
 
Valentin Crettaz
Gold Digger
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The links contain both a solution for IE and FF.

Your code, however, won't work if Flash is not available or cannot be installed for security reasons (i.e., in highly secure intranets!)
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JavaScript solutions normally do not work now with the newer versions of browsers because the copy,paste can be diabled. This question has come up a lot lately on other forums.

So if the option is not enabled in the browser and flash is disabled, people are stuck using their own fingers to right click or ctrl-c.

Eric
[ September 28, 2007: Message edited by: Eric Pascarello ]
 
To do a great right, do a little wrong - shakepeare. twisted little ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!