Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> One Click Copy And Paste To Clipboard, in simple Javascript
BuffaloHELP
post Jan 16 2006, 04:49 AM
Post #1


Desperately seeking "any key" to continue...
Group Icon

Group: Admin
Posts: 3,438
Joined: 23-April 05
From: Trap17 storage box
Member No.: 6,042



I've been search the web for few weeks to see if Java can do one click copy and paste function to the clipboard and then I can just Ctrl-V the copied "texts." I initially got this idea when I began to approve hosting application. Instead of writing the same message over and over again, I decided to make me a page where I can simply copy the code to appropriate answers. And seems like my laziness is the mother of inventions laugh.gif Instead of doing Ctrl-A, Ctrl-C then Ctrl-V to the post board I started to dream about a button that will select my pre-written message and copy at the stroke of one single click.

I have search the web but they were either not working properly or it was way too long for me to understand and work it in with my own webpage. But accidentally I found this script that is short and does the job like no other I have ever seen. So I'd like to share it with you.

HTML
<html>
<head>
<title>Javascript for one-click highlight and copy to clipboard</title>
</head>
<script language='Javascript'>
function doact(d)
{
var doc = eval("document.readme."+d);
cp = doc.createTextRange();
doc.focus();
doc.select();
cp.execCommand("Copy");
}
</script>
<form name="readme">
<body>
<center>
<TEXTAREA name="text1" cols="30" rows="5">
Your basic HTML codes can be entered here.
Do not worry about HTML codes interfering with your regualr web page since the <TEXTAREA> cannot excute any codes at all.
</TEXTAREA><BR>
<input onclick="doact('text1')" type="button" value="Copy Code">

<BR><BR>

<TEXTAREA name="text2" cols="30" rows="20">
This TEXTAREA is to demonstrate the inclusion of the second parameter.

You can even skip lines or create list

1
2
3
4
5
</TEXTAREA><BR>
<input onclick="doact('text2')" type="button" value="Copy Code">
</center>
</body>

</html>

Couple of key elements you should be aware
This code is currently 100% compatible with IE. I'm still working on FireFox but I was told that I need to edit pref.js in "about" page. If you read this article Security Issues with Ctrl-C and Clipboard by cse-icons and made the change to your browser you need to undo or reverse the effect when executing this script. I uploaded to my personal webspace and made only the TRUSTED site to execute this script. You can see this script in action by visiting this page.

Few things I had issues when making this script working
1. Make sure that your <FORM name="*****"> is equal to var doc = eval("document.*****."+d);

2. <TEXTAREA name="text1"> is the same name in each input botton, i.e.
HTML
<input onclick="doact('text1')" type="button" value="Copy Code">

3. However it is written in the TEXTAREA is how it will appear when you Ctrl-V or paste to your page/notepad. So it will obey every format you include such as every space line, indents, tabs and even break of sentence or code.

4. I have included the secondary TEXTAREA to demonstrate the ability to add additional code copy.

Since I found this code on the web I cannot take the credit for it. I merely took it apart and made it to work with what I intended. I couldn't find the author to this very short yet effective code. Perhaps one of you may know. This simple javascript was the shortest and most intuitive that I have seen so far. As soon as I get it working with FireFox I'll let you all know.
Go to the top of the page
 
+Quote Post
Richard
post Jan 16 2006, 04:54 AM
Post #2


Member [Level 1]
****

Group: Members
Posts: 56
Joined: 15-January 06
Member No.: 17,166



i have seen this before but they where little boxes but this is big and cool
Go to the top of the page
 
+Quote Post
WBBulldogs
post Jan 16 2006, 06:47 PM
Post #3


Newbie [Level 2]
**

Group: Members
Posts: 37
Joined: 16-January 06
From: Colorado Springs
Member No.: 17,185



Like Richard Said. I have seen little versions of this but this is way bigger than I've ever seen. I'm glad you found something to help you out on this site. I can't wait to get my webpage active too!
Go to the top of the page
 
+Quote Post
Plenoptic
post Jan 16 2006, 07:25 PM
Post #4


Trap Double Mocha Member
***************

Group: [HOSTED]
Posts: 2,220
Joined: 5-November 05
From: That one place over there...
Member No.: 13,830



I have seen that but never really figured out how to do it. Thanks for sharing the code Buffalo. That'll be helpful on my site when I have to do stuff like that. I almost was gonna tell you that it doesn't work. I didn't realize that I was using firefox I thought I was using Internet Explorer but then I noticed and it works fine. Very nice.
Go to the top of the page
 
+Quote Post
delivi
post Jan 16 2006, 07:31 PM
Post #5


Trap Grand Marshal Member
***********

Group: [HOSTED]
Posts: 1,300
Joined: 11-January 06
From: Chennai, India
Member No.: 16,932



Good work dude thats the spirit share what you know with others smile.gif Keep the work going on pal.
Go to the top of the page
 
+Quote Post
iGuest
post Mar 20 2008, 10:46 AM
Post #6


Trap Double Mocha Member
***************

Group: Members
Posts: 2,360
Joined: 21-September 07
Member No.: 50,369



About this javascipt
One Click Copy And Paste To Clipboard

I need something to copy a table into an outlook new message window...
This js copies the html code and I was wondering if someone could help me with this. So I need an ideea to make a js that copies the table as table not as html code.
10x,
Kat
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Auto Run Java Program(11)
  2. Javascript Slideshow Tutorial(3)
  3. Javascript Close Window(12)
  4. Adding Rows & Columns In Html Table Using Javascript(1)
  5. I'm Making My Own Javascript Only Rpg :d(7)
  6. What's The Relationship Between Javascript And Java(5)
  7. Javascript : No Right Click Script !@(12)
  8. Hiding <div> Boxes With Javascript(8)
  9. Highlight A Word In Javascript. Help!(2)
  10. One Click To Copy Script(4)
  11. How Do You Make A Javascript Calculator?(11)
  12. Help With Javascript Calculator Returning "nan"(2)
  13. Great Javascript Script Source(2)
  14. Web Applications: J2ee Or Javascript/css/html(1)
  15. Opera Browser + Javascript + Embeded Sound(0)
  1. Javascript - What's Your Browser?(3)
  2. Javascript Events Not Working For Ie(6)
  3. I`m New To Javascript.(5)
  4. Special Wii Javascript(2)
  5. Javascript Error(2)
  6. Is It Possible To Create A Web Based Mmo In Javascript?(4)
  7. Helpful Registry Edit For Java Programmers(2)
  8. Capturing Username Of Computer(3)
  9. Javascript Object Node Referencing Help(5)
  10. Flash And Javascript Interaction(1)
  11. Document.write & Noscript Questions (javascript)(1)
  12. Java Vs Javascript(11)
  13. Adjusting Rows/cols Of Frames In Frameset Using Javascript Is Not Working In Firefox 3 Is Not Working(4)


 



- Lo-Fi Version Time is now: 26th July 2008 - 03:48 PM