navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

Microsoft MVP

 

Adding a JavaScript Copy to Clipboard function

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> General Web Development >> Adding a JavaScript Copy to Clipboard function
Page: [1]
 
BobbyDouglas

 

Posts: 5456
Joined: 5/15/2003
From: Arizona
Status: offline

 
Adding a JavaScript Copy to Clipboard function - 3/1/2004 1:14:00   
I am trying to add a button that will "Copy contents to clipboard".

Unfortunately I am not getting the result I want. Any ideas what I should modify/add?

Here is what I am currently working with:
Page: mrbobdouglas[dot]com/testing/email_encryption_test.php
Script: mrbobdouglas[dot]com/testing/email.js

_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge
Giomanach

 

Posts: 6091
Joined: 11/19/2003
From: England
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 3/1/2004 3:56:24   
Bobby

This is one of my own, written off the top of my head:

<script language="javascript" type="text/javascript">
function copyText(theSel) {
if (!document.all) return; // IE only
theForm = theSel.form;
theForm.copyArea.value=theSel.options[theSel.selectedIndex].value;
r=theForm.copyArea.createTextRange();
r.select();
r.execCommand('copy');
}
</script>

HTH

Dan

_____________________________




(in reply to BobbyDouglas)
gorilla

 

Posts: 2974
From: Denmark
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 3/1/2004 8:11:28   
http://www.htmlgoodies.com/beyond/clipboard.html

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

IE only.

_____________________________

Mháircaish

Signature self-censored to protect the sensibilities of the thin-skinned :).

May we never confuse honest dissent with disloyal subversion. – Dwight D. Eisenhower



(in reply to Giomanach)
BobbyDouglas

 

Posts: 5456
Joined: 5/15/2003
From: Arizona
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 3/1/2004 9:55:40   
Thanks for the suggestions.

I have added some code to the script, unfortunately it is not quite working right. The email.js file that the one that contains basically all of the code.

Before the textarea that will be copied:
<SCRIPT language="JavaScript">
<!--
function highlightmetasearch() {
document.post.message.select(); document.FORMNAME.TEXTAREANAME.focus();
}
function copymetasearch() {
highlightmetasearch();
textRange = document.post.message.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy");
alert("This post has been copied to your clipboard.");
   }
// -->
</SCRIPT>


To display the button:
<script language="JavaScript" type="text/javascript">
<!--
if ((navigator.appName=="Microsoft Internet Explorer")&&(parseInt(navigator.appVersion)>=4)) {
document.write('<INPUT type="button" class="button" value="Copy" onClick="copymetasearch();">');
} else {
document.write('<INPUT type="button" class="button" value="HIGHLIGHT TEXT" onClick="highlightmetasearch();">');
}
// -->
</script>


_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge

(in reply to gorilla)
BobbyDouglas

 

Posts: 5456
Joined: 5/15/2003
From: Arizona
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 3/1/2004 15:24:10   
Just updating here... THis is what I need to do next, but I need some help with it....

I am trying to figure out how to include this:
<script language="JavaScript" type="text/javascript"> 
<!-- 
if ((navigator.appName=="Microsoft Internet Explorer")&&(parseInt(navigator.appVersion)>=4)) { 
document.write('<INPUT type="button" class="button" value="COPY TO CLIPBOARD" onClick="copymetasearch();">'); 
} else { 
document.write('<INPUT type="button" class="button" value="HIGHLIGHT TEXT" onClick="highlightmetasearch();">'); 
} 
// --> 
</script>


Inside of this function:
    Encrypt(value);
    numArray++;
    document.write ("<table border='0' cellpadding='3' width='80%' align='center'>");
    document.write ("    <form action='email_encryption.php' method='get' name='emailencrypt'>");
    document.write ("    <tr><td valign='bottom'>");
    document.write ("            <input type='submit' class='input' name='submit' value='Submit' />");
    document.write ("        </td>");
    document.write ("        <td>");
    document.write ("            <i>Enter info to encode</i> <br />");
    document.write ("            <input type='text' class='input' name='encode' size='55' value='");
    document.write (valueDisplay);
    document.write ("' />  ");
    document.write ("            <input type='text' class='input' name='numarray' size='3' value='");
    document.write (numArray);
    document.write ("' />");
    document.write ("        </td>");
    document.write ("    </tr>");
    document.write ("    </form>");
    document.write ("    <tr><td></td>");
    document.write ("        <td valign='bottom'>");
    document.write ("        <form name='encryptedemail'>");
    document.write ("            <textarea class='input' name='encrypted' rows='" + outLines + "' cols='64'>");
    document.write (javEncrypted);
    document.write ("</textarea>");
    document.write ("        </form>");
    document.write ("        </td>");
    document.write ("    </tr>");
    document.write ("</table>");


Any ideas?

_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge

(in reply to BobbyDouglas)
gorilla

 

Posts: 2974
From: Denmark
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 3/2/2004 9:15:53   
Completely off the top of my head but wouldn't something like:

document.write("<script src='var.js'><\/script>");

do it?

Still off the top of my head hmmmm:

If document.write doesn't do the trick try to alert()

interesting problem - I'd love to hear how you got on.

< Message edited by gorilla -- 3/2/2004 9:25:36 >


_____________________________

Mháircaish

Signature self-censored to protect the sensibilities of the thin-skinned :).

May we never confuse honest dissent with disloyal subversion. – Dwight D. Eisenhower



(in reply to BobbyDouglas)
BobbyDouglas

 

Posts: 5456
Joined: 5/15/2003
From: Arizona
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 3/2/2004 9:56:41   
Ahhhh. Gorilla points out the obvious... let me try that. Can't believe I didn't think about it :)

_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge

(in reply to gorilla)
BobbyDouglas

 

Posts: 5456
Joined: 5/15/2003
From: Arizona
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 3/2/2004 10:05:58   
Hmmm, both ways did not quite work...

_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge

(in reply to BobbyDouglas)
ganhoc

 

Posts: 1
Joined: 5/10/2004
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 5/10/2004 4:56:11   
Hi everybody. :)I'm new member. I have the same trouble. I want to creat a "copy contents to clipboard" button. I saw all ur solution, but my problem is that the text I want to copy was created by a java's function (it's the script using for composing mails in Yahoo!Mail, you can format and add hyperlink to the text ). I knew how to get the text from the text area, but from that edit zone......, I have no idea. Can you help me??
And I want to check the text'length, too. Thank you!!:)

(in reply to BobbyDouglas)
AMysticWeb

 

Posts: 855
Joined: 10/23/2002
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 5/11/2004 2:34:28   
Hi Bobby,

I am putting in my two cents, even though it may never increase in value.

Since the Copy to Clipboard function seems to be basically restricted to IE, from what I understand, why not just use a highlight all script and let them right click to copy?

Of course this is a form function and might not look pretty, but it might still be effective.

_____________________________

Hope I have been of some help,
Micheal

[URL=http://web.archive.org/web/20060101013129/http://www.frontpageforms.com/]FrontPageForms.com-Archive Version[/URL]
I am living Proof that Viral Procrastination exists!

(in reply to ganhoc)
BobbyDouglas

 

Posts: 5456
Joined: 5/15/2003
From: Arizona
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 5/11/2004 11:10:36   
Well I have seen others that work in Mozilla. At least I think so.. :)

Damn this thread is getting a lot of hits...

< Message edited by BobbyDouglas -- 5/11/2004 11:10:59 >


_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge

(in reply to AMysticWeb)
Nigel

 

Posts: 382
Joined: 7/24/2002
From: Wirral - UK
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 5/12/2004 7:44:16   
Yes Bobby - you seem to have a knack of creating topics that get read a lot. 2 of them (this one and the 360 tour) have about 3500 hits between them!

Nigel

_____________________________

Innerview
Web Design - Virtual Tours - 360 Panoramas - Shopping carts

(in reply to BobbyDouglas)
AMysticWeb

 

Posts: 855
Joined: 10/23/2002
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 5/12/2004 10:48:58   
Hi Bobby,

Yes, I have run across one or two that are set up for IE and Mozilla, but still none for NS.

_____________________________

Hope I have been of some help,
Micheal

[URL=http://web.archive.org/web/20060101013129/http://www.frontpageforms.com/]FrontPageForms.com-Archive Version[/URL]
I am living Proof that Viral Procrastination exists!

(in reply to Nigel)
BobbyDouglas

 

Posts: 5456
Joined: 5/15/2003
From: Arizona
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 5/12/2004 16:59:17   
Are we talking about NS4.x?

I will never install NS on my computer. Only time I encounter it is at school, even then I have the choice to use NS or IE.

_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge

(in reply to AMysticWeb)
AMysticWeb

 

Posts: 855
Joined: 10/23/2002
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 5/12/2004 17:07:47   
Hey Bobby,

Far as I know it won't work in NS period.

I don't use NS myself, but I keep it around for browser preview.

I have 6.1 on my PC. It's just that everything I have seen about the copy fields scripts is that they don't work in NS period. And, I think that probably millions of people are secretly using NS.

I suggested the Highlight All because I use it a lot on my site.

_____________________________

Hope I have been of some help,
Micheal

[URL=http://web.archive.org/web/20060101013129/http://www.frontpageforms.com/]FrontPageForms.com-Archive Version[/URL]
I am living Proof that Viral Procrastination exists!

(in reply to BobbyDouglas)
BobbyDouglas

 

Posts: 5456
Joined: 5/15/2003
From: Arizona
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 5/12/2004 17:11:59   
I suggested the Highlight All because I use it a lot on my site
-- I bet it works fine like that, I just wanted something to do both highlight and copy :)

Shouldn't it work in NS if it works in an earlier version of Mozilla? I always thought the gecko browsers loaded just about the same?

_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge

(in reply to AMysticWeb)
AMysticWeb

 

Posts: 855
Joined: 10/23/2002
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 5/13/2004 0:26:29   
Hey Bonny,

Persistence pays off.

Just found one Here that claims to work in all three moz,ns & IE, with some tweaking.

Glad you kept this thread going. I might never have found this. I have poked around I don't know how many times, without running into this.

This is the first one I ran across.

_____________________________

Hope I have been of some help,
Micheal

[URL=http://web.archive.org/web/20060101013129/http://www.frontpageforms.com/]FrontPageForms.com-Archive Version[/URL]
I am living Proof that Viral Procrastination exists!

(in reply to BobbyDouglas)
madramire

 

Posts: 1
Joined: 12/13/2005
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 12/13/2005 7:48:37   
Been reading your posts here, found it very useful to test each script placed up here for copy to clipboard.

The problem I am experiencing is that I need to use a form to create a back up of inforamtion inserted.

It won't be e-mailed, I want to copy the data from several fields... text areas + input fields.

I can get only one text are to copy, the last one usnig the following script:
<SCRIPT language="JavaScript">
<!--
function highlightmetasearch() {
document.SOAP.PROBLEM_DESCRIPTION.select(); document.SOAP.PROBLEM_DESCRIPTION.focus();
}
function copymetasearch() {
highlightmetasearch();
textRange = document.SOAP.PROBLEM_DESCRIPTION.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy");
}
function highlightmetasearch() {
document.SOAP.IMPACT.select(); document.SOAP.IMPACT.focus();
}
function copymetasearch() {
highlightmetasearch();
textRange = document.SOAP.IMPACT.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy");
}
function highlightmetasearch() {
document.SOAP.RESOLUTION.select(); document.SOAP.RESOLUTION.focus();
}
function copymetasearch() {
highlightmetasearch();
textRange = document.SOAP.RESOLUTION.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy");
}
function highlightmetasearch() {
document.SOAP.HARDWARE.select(); document.SOAP.HARDWARE.focus();
}
function copymetasearch() {
highlightmetasearch();
textRange = document.SOAP.HARDWARE.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy");
}
function highlightmetasearch() {
document.SOAP.SOFTWARE.select(); document.SOAP.SOFTWARE.focus();
}
function copymetasearch() {
highlightmetasearch();
textRange = document.SOAP.SOFTWARE.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy");
}
function highlightmetasearch() {
document.SOAP.ERROR_MESSAGES.select(); document.SOAP.ERROR_MESSAGES.focus();
}
function copymetasearch() {
highlightmetasearch();
textRange = document.SOAP.ERROR_MESSAGES.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy");
}
function highlightmetasearch() {
document.SOAP.Engineer_Assessment.select(); document.SOAP.Engineer_Assessment.focus();
}
function copymetasearch() {
highlightmetasearch();
textRange = document.SOAP.Engineer_Assessment.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy");
}
function highlightmetasearch() {
document.SOAP.Next_Action_on_Customer.select(); document.SOAP.Next_Action_on_Customer.focus();
}
function copymetasearch() {
highlightmetasearch();
textRange = document.SOAP.Next_Action_on_Customer.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy");
}
function highlightmetasearch() {
document.SOAP.Next_Action_on_Microsoft.select(); document.SOAP.Next_Action_on_Microsoft.focus();
}
function copymetasearch() {
highlightmetasearch();
textRange = document.SOAP.Next_Action_on_Microsoft.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy");
}
function highlightmetasearch() {
document.SOAP.Next_Agreed_Contact_Date.select(); document.SOAP.Next_Agreed_Contact_Date.focus();
}
function copymetasearch() {
highlightmetasearch();
textRange = document.SOAP.Next_Agreed_Contact_Date.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy");

alert("Paste the Contents of the Template into your Clarify Case by Clicking Ctrl+v");
}
// -->
</SCRIPT>

It doesn't actually copy all the fields, I needa script that allows all input fields to be copied and then a reset button for all the fields.

I will also be adding a timer function eventually and I would like to be able to use the reset button the reset that to 0 too.

Any ideas how I can manipulate the script above to copy all the fields before we get into the rest?

(in reply to BobbyDouglas)
cmcdaniel

 

Posts: 1
Joined: 2/21/2007
Status: offline

 
RE: Adding a JavaScript Copy to Clipboard function - 2/21/2007 2:31:22   
horay for javascript.... why don't we use it??? here's a nice copy command you can use anywhere in script with a variable or not.
window.clipboardData.setData('text',myVar);

where myVar is the variable being copied.

This works too...
window.clipboardData.setData('text','This has been copied to your clipboard.');


...:)



(in reply to madramire)
Page:   [1]

All Forums >> Web Development >> General Web Development >> Adding a JavaScript Copy to Clipboard function
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts