May 17, 2008

One Click Copy And Paste To Clipboard - in simple Javascript

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

free web hosting

One Click Copy And Paste To Clipboard - in simple Javascript

BuffaloHELP
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.

 

 

 


Reply

Richard
i have seen this before but they where little boxes but this is big and cool

Reply

WBBulldogs
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!

Reply

Plenoptic
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.

Reply

delivi
Good work dude thats the spirit share what you know with others smile.gif Keep the work going on pal.

Reply

Trap FeedBacker
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

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. firefox clipboard copy - 3.95 hr back.
  2. copy input text to clipboard javascript - 6.53 hr back.
  3. java clipboard paste image ctrl-v - 7.45 hr back.
  4. firefox javascript copy clipboard - 19.85 hr back.
  5. javascript copy to clipboard url of input box - 20.62 hr back.
  6. js copy to clipboard firefox - 21.02 hr back.
  7. javascript onclick copy - 21.67 hr back.
Similar Topics

Keywords : click, copy, paste, clipboard, simple, javascript

  1. Java Vs Javascript
    (8)
  2. Document.write & Noscript Questions (javascript)
    (1)
    I am trying to use javascript to include a stylesheet depending on the user's resolution. The
    HTML CODE <head>    <meta http-equiv="Content-Type" content="text/html;
    <?php echo _ISO; ?>" />    <?php if ($my->id) {
    initEditor(); } ?>    <?php mosShowHead(); ?>   
    <noscript><link rel="stylesheet" type="text/css"
    href="http://www.highimpactart.org/templates/_HighImpactArt_/1024/1024.css"
    /></noscript>    <script type="....
  3. Flash And Javascript Interaction
    swfobject js questions (1)
    I don't know if anyone on here is familiar with this script. You can check it out here .
    Basically it's a script that is supposed to give you javascript control over a flash object. I
    am using it for a flv player. My question is this. I would like to display the current file's
    title in a span element on the page, but the function described to gather the information for the
    current file doesn't seem to work for me. The function, as outlined on on this page looks
    like this: CODE function getUpdate(typ,pr1,pr2,swf) {   if(typ == &#....
  4. Javascript Object Node Referencing Help
    (5)
    I've got two buttons with an onclick event to set the hidden input field to a certain value then
    continue submitting the form. I have more than one form on display on the page and I don't want
    to use ids. Is there a way I can reference it from the button/button onclick event? the forms is
    laid out like this echo" "; echo" "; echo" Edit "; echo" Delete "; echo" ";
    So basically the idea is to fire off new_modify function and start referencing the hidden input type
    with name of do and set it to the supplied argument then continue submitting t....
  5. Capturing Username Of Computer
    using javascript, is it possible? (3)
    I wondering if it is possible to try and make a java script to get the computer username and log it?
    /huh.gif" style="vertical-align:middle" emoid=":huh:" border="0" alt="huh.gif" /> edit Topic
    title ....
  6. Helpful Registry Edit For Java Programmers
    Command Prompt on right click menu (2)
    With this registry edit you can easily open the current folder in prompt without going through any
    Change Directory commands (cd). This is useful for people like me who are programming in JAVA, and
    every time to create class files and test them I have a diificult time just entering the commands in
    Prompt. But if you don't want to use this registry edit you can create the directory in
    C:\ drive like C:\files so you have to navigate very little in prompt. If you are
    experienced in regedit you can do it yourself shown below OR download the attachment and app....
  7. Is It Possible To Create A Web Based Mmo In Javascript?
    And could there be free movement without reloading the page? (4)
    I would like to get some information before launching myself to the JS libraries. Is it possible to
    load maps or images and with the press of a button "scroll" or move the image inside some kind of
    window up, down, left or right? It would be like scrolling an image sideways, upwards or downwards.
    I would also like to know if multiple connections can be made and lets say there was a user
    standing in the location (127, 160) of the map, would there be the possibility of loading the image
    of that player? Maybe with database connections and storing their information there?....
  8. Javascript Error
    Error "missing ) in parenthetical" with JSON statment (2)
    Hello! I'm trying to execute following code: CODE a=new Array();
        a=eval("("+responseText+")");     for (prop in a) {
            e=document.getElementById(prop)         if (e) {e.innerHTML=a[prop]}
    and I recieve error in CODE a=eval("("+responseText+")");
    what's wrong? responseText it's result from php2js() function. Apache 2.2.6/PHP5.2.5/MySQL
    5.0.45....
  9. Special Wii Javascript
    New Javascript Objects for Wii (2)
    I found on Nintendo.com a while back some new javascript objects dealing with the Wii Remote. I
    have decided to post a link to these new Javascript objects here. Wii javascript These new
    Javascripts can detect whether or not a Wii Remote is enabled, the position of the pointer, and even
    the tilt of the remote. It also has an object that determines the keypress of the Wii. These can be
    very useful for Wii sites. Maybe have a menu load with AJAX when the remote is tilted. Add button
    functionality such as when the A and B button are pressed, the form is submitted. Just....
  10. I`m New To Javascript.
    (5)
    Does anybody know where I can find a good site to teach me more than I already know. I know about
    functions and how to set up alert scripts. I really wanna make a counter script.....
  11. Javascript Events Not Working For Ie
    (6)
    I just made this little html file and I used javascript to show which arrows you're pressing. It
    just says the key code, but only for the arrows, so it will say "37, 38, 39, 40" if you're
    pushing all the arrows. When you let go of the arrows, it won't show that value. It works
    perfectly in Firefox, but I can't get it to run in Internet Explorer. The little notification
    bar down in the bottom left of the window says there's an error, and it just sits there. All I
    used was a function for onKeyDown and onKeyUp on the body, and every 10 milliseconds it sh....
  12. Javascript - What's Your Browser?
    (3)
    Here is the code that i picked up from a Javascript book that will tell you wether you are using
    Firefox or Internet explorer. obviously the (navigator.appName ==" browser name ") can be changed
    to different browsers. CODE <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 -
    Transitional//EN"> <html xmlns="http://www.w3.org/1999/xhtml">
    <head>          <title>What's your browser?</title> </head>
    <body bgcolor="#FFFFFF"> <h2>                    <script
    language="....
  13. Opera Browser + Javascript + Embeded Sound
    Embeded sound works in IE, but not in Opera (0)
    Hello! Here is the problem. There is an Embed object, created like this: function
    createWMPEmbedMarkup(src, id, baseurl) { // For choice, using the DOM instead of a string
    // so the caller gets a node. (Its childNode could be used if you don't want the whole p
    element) // Then, if markup is needed instead, innerHTML is available. var x =
    document.createElement("embed"); x.setAttribute("FileName", src);
    x.setAttribute("type", "application/x-mplayer2"); x.setAttribute("AutoStart", "0");
    x.setAttribute("id....
  14. Web Applications: J2ee Or Javascript/css/html
    (1)
    I'm currently programming web applications using AJAX/CSS/HTML and they're pretty
    cross-browser. However when I heard of this language J2EE I had second thoughts. But I ran into GWT
    (Google Web Toolkit) which compiles Java code to Javascript/HTML. With this said, my mind tells me
    that Java developers desire to use Javascript/HTML languages to create web applications over Java.
    So, which one should I start developing web applications in? Java? or Javascript....
  15. Great Javascript Script Source
    Great Javascript script source (2)
    Are you find great javascript source !!! try this >>> http://www.dynamicdrive.com ....
  16. Help With Javascript Calculator Returning "nan"
    (2)
    Hello all, thought maybe I could get a little help with a problem I was having with some Javascript
    on this forum. I recently posted about adding some type of script to my page that calculated a
    customers custom computer system price by assigning each form option a dollar value. I have done so,
    with a script that seems like it would work, but am having some problems. I feel that I have the
    script correctly in place, but when the user selects their computer options a total of "NaN" returns
    at the bottom of the page. You can see what I mean here: www.plugcomputers.com/a....
  17. How Do You Make A Javascript Calculator?
    in a form (11)
    Hi, does anyone know how you would make a html form with javascript where it calculates number... i
    will demonstrate below to make it more clear what i mean.. i want the form to have like three
    buttons, MULTIPLY,DIVIDE. AND RESET.. and than i want it to have the fields where you type in the
    numbers and it gives you the answer.. so its Field 1 * OR / Field 2 = Field 3 . does anyone know
    how to make this work? i basiaclly want all the three functions to work with the same form. this is
    a project grade in my web design class but i need help. Thanks....
  18. One Click To Copy Script
    In IE6 it works, but not FF2 (4)
    Could everyone have a look at this and suggest how to get this working in FF and/or maybe Opera???
    If you look at this link using IE6 (possibly IE7), you should be able to click on the buttons to
    copy the textarea to the clipboard and then paste it into the blank textarea. Works great in IE, but
    not Firefox or Opera or Netscape Browsers. Link Demo: Here Bring your IE Browser. As per the
    above, it won't work in FF. Javascript for one-click highlight and copy to clipboard
    <script type="text/javascript"> function doact(d) { var doc = eval....
  19. Highlight A Word In Javascript. Help!
    BBCode (2)
    Hi, I'm making a forum right now, and i'm having some trouble with BBCodes. I want it so
    when they click a button it will add the bbcode and highlight (or place the cursor between) the
    code . Let me clarify, I want a button to be clicked, it adds code to the textarea and places the
    cursor between the tags. Example: CODE [b] (cursor here)  [/b]
    [b] | [/b] The cursor is between the two tags. I REALLY appreciate it, i've
    search so long with no luck.....
  20. My Little Javascript
    Need Some Debugging Help (0)
    Ok, to start, the purpose of the script. I'm trying to make a script that puts a link on every
    page on an Invisionfree forum (IPB 1.3) that takes you to a thread and automatically put in the url
    from which you clicked. I already have the whole thing working, but when I go to edit my signature,
    it inputs most of the url into the box. It replaces my whole sig with that, so it's a big
    problem. The code: CODE This part makes the link on every page. <script
    LANGUAGE="JavaScript">              <!--           
    document.write('<....
  21. Help With Javascript Calculator On My Website Please!
    (1)
    Hello all, As many of you may know my website, www.PlugComputers.com is in the business of building
    custom gaming computers. I need some help coding one part of my site and I have never been too good
    at javascript. First off, I'm assuming what I am wanting to do would be done with
    javascript...my problem is as follows: On our build customization pages (
    www.PlugComputers.com/intelschedule.php for example) vistors can go though the page and select
    which components they want for their computer. The problem is people are selecting things they
    really dont know much a....
  22. A Simple Javascript Help Required
    (3)
    Can somebody help me in creating a very simple javascript.. for example, the following code is
    example to delete a row from mysql.. all i want to do is.. that, when i click on delete, it gives a
    popup window , asking me if i really want to delete the row.. if i say Yes then it takes the
    action.. but if i say no then it takes back.' CODE $result =
    mysql_query("select * from comments order by id desc limit 10"); //the while loop
    while($r=mysql_fetch_array($result)) { //getting each variable from the
    table $id = &....
  23. Javascript
    (6)
    I've lately outlined myself and found out that i'm very well rounded in PHP/SQL, HTML/XHTML,
    XML, and Perl. No C/C++, Java, nor Javascript. So. I thought about it, if I can do all of the server
    side scripting and such, I need to learn Javascript. Currently, I can do a thing with javascript. I
    don't even know the basics of it. I only feeds of other's scripts thats posted in libraries
    amonst the net. But lemme get down to the point. This is a plea for help. Does anyone know of a
    good, effective Javascript tutorial except WCSchools? Perhaps a place you learn....
  24. Destroying Variables In Javascript
    Destroying variables in javascript (7)
    how do you delete the contents of a variable in javascript? Any ideas?....
  25. Hiding <div> Boxes With Javascript
    Javascript Help #1 (8)
    This is my first help post in this Java/JavaScript section. Can someone write/find me a piece of
    code that will hide boxes? Preferred stuff: There is a bar that has the subtitle of the box
    contents. A button on the right side of the bar shows and hides the div box. Contents are in a box
    with a border and slides in and out of the bar smoothly and relatively quickly. Box MUST be
    customizable using CSS internal/external stylesheets . Any help would be appreciated. All codes
    will be tested and best code be selected.....
  26. What's The Relationship Between Javascript And Java
    are they the same or different (5)
    I think most of you always confuse about java and javascript .So I make this topic to talk about it.
    Javascript and Java ,they have the same first four letter. Java and Javascript is the two language
    is very popular in the web world.Java is the general-purpose programming language that you can
    create an application or an applet.Javascript is a script language that looks sort of like java;with
    it you can do various nifty things in web pages.They are independent languages ,used for different
    purposes.If you are interesting in creating a website you should learn how to w....
  27. I'm Making My Own Javascript Only Rpg :d
    earliest beta perhaps (7)
    Well I randomly decided to make an rpg. So far its all in javascript, and that's how I intend to
    keep it. Eventually you will be able to save with a permanent cookie or by getting an encrypted
    code. Right now you can only walk around and go to 2 maps. I have used preloading, and the maps load
    extremely fast. But there is one problem, maybe you guys could help but I mostly just posted to tell
    you guys something /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif"
    />. Well the problem is the character images load extremely slow and i know wh....
  28. Javascript Close Window
    Javascript close window (10)
    Hi does anyone have a code to close the browser window. This code needs to be used to close an
    actual full sized window, not a pop-up window.....
  29. Javascript Slideshow Tutorial
    How to make a slideshow in JavaScript (3)
    JavaScript Slideshow Tutorial I'm going to show you how to make a impressive JavaScript
    slideshow. First, you're probably asking: why would I want to make a slideshow in JavaScript?
    There are a number of reasons. First, you don't have to build a new HTML page for each picture.
    Secondly, the page will load much faster because the of the compactness of the page. Ok let's
    get started with this example. First we'll add a <script> tag in the of our HTML
    document. In that script tag we will build the following: CODE      first = 1;      la....
  30. Javascript resources?
    ie, a book. (9)
    Hi, I'm trying to learn Javascript. The thing is, I don't have any reference material
    around, so I'm gonna need to buy a book or something. Are there any which you would recommend? I
    looked on some websites but there are literally hundreds of books of this kind. /blink.gif"
    style="vertical-align:middle" emoid=":blink:" border="0" alt="blink.gif" /> (in answer to the
    below, sorry sauron, didnt see that one)....

    1. Looking for click, copy, paste, clipboard, simple, javascript

Searching Video's for click, copy, paste, clipboard, simple, javascript
Similar
Java Vs
Javascript
Document.wri
te &
Noscript
Questions
(javascript)
Flash And
Javascript
Interaction
- swfobject
js questions
Javascript
Object Node
Referencing
Help
Capturing
Username Of
Computer -
using
javascript,
is it
possible?
Helpful
Registry
Edit For
Java
Programmers
- Command
Prompt on
right click
menu
Is It
Possible To
Create A Web
Based Mmo In
Javascript?
- And could
there be
free
movement
without
reloading
the page?
Javascript
Error -
Error
"missing
) in
parenthetica
l" with
JSON
statment
Special Wii
Javascript -
New
Javascript
Objects for
Wii
I`m New To
Javascript.
Javascript
Events Not
Working For
Ie
Javascript -
What's
Your
Browser?
Opera
Browser +
Javascript +
Embeded
Sound -
Embeded
sound works
in IE, but
not in Opera
Web
Applications
: J2ee Or
Javascript/c
ss/html
Great
Javascript
Script
Source -
Great
Javascript
script
source
Help With
Javascript
Calculator
Returning
"nan&qu
ot;
How Do You
Make A
Javascript
Calculator?
- in a form
One Click To
Copy Script
- In IE6 it
works, but
not FF2
Highlight A
Word In
Javascript.
Help! -
BBCode
My Little
Javascript -
Need Some
Debugging
Help
Help With
Javascript
Calculator
On My
Website
Please!
A Simple
Javascript
Help
Required
Javascript
Destroying
Variables In
Javascript -
Destroying
variables in
javascript
Hiding
<div>
Boxes With
Javascript -
Javascript
Help #1
What's
The
Relationship
Between
Javascript
And Java -
are they the
same or
different
I'm
Making My
Own
Javascript
Only Rpg :d
- earliest
beta perhaps
Javascript
Close Window
- Javascript
close window
Javascript
Slideshow
Tutorial -
How to make
a slideshow
in
JavaScript
Javascript
resources? -
ie, a book.
advertisement



One Click Copy And Paste To Clipboard - in simple Javascript



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE