IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
 
Reply to this topicStart new topic

One Click To Copy Script

, In IE6 it works, but not FF2


jlhaslip
no avatar
Insert Custom Title Here
*******************
Group: [MODERATOR]
Posts: 4,908
Joined: 24-July 05
From: Linux, DOS and Windows…the good, the bad and the ugly
Member No.: 9,787
Spam Patrol
myCENT:6.20



Post #1 post Feb 17 2007, 06:30 AM
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.

[codebox]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Javascript for one-click highlight and copy to clipboard</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" >
<meta http-equiv="Content-Style-Type" content="text/css" >
</head>
<body>

<script type="text/javascript">
function doact(d)
{
var doc = eval("document.readme."+d);
cp = doc.createTextRange();
doc.focus();
doc.select();
cp.execCommand("Copy");
}
</script>
<div>
<form name="readme" action="#">
<p style="float:left">
<textarea name="text1" cols="10" rows="2">
1. -Your basic HTML codes can be entered here.</textarea>
<br>
<input onclick="doact('text1')" type="button" value="Quote">
</p>

<p style="float:left">
<textarea name="text2" cols="30" rows="2">
2. -This textarea is the second textbox for copying.
2. -This textarea is the second textbox for copying.</textarea>
<br>
<input onclick="doact('text2')" type="button" value="Longer Quote">
</p>

<p style="float:left">
<textarea name="text3" cols="40" rows="2">
3. -This textarea is to demonstrate the inclusion of the third textbox for copying.
3. -This textarea is to demonstrate the inclusion of the third textbox for copying.
3. -This textarea is to demonstrate the inclusion of the third textbox for copying.</textarea>
<br>
<input onclick="doact('text3')" type="button" value="Still A Longer Quote">
<br style="clear:both" />
</p>
<p style="clear:both" ></p>
<p><strong>Add Information To <em>This Work Area</em> To Build Your Posting</strong></p>
<p>
<textarea name="text4" cols="60" rows="8">
</textarea>
<br>
<input onclick="doact('text4')" type="button" value="Main Text area">
<input type="reset" value="Clear The Form">
</p>
</form>
</div>
</body>

</html>[/codebox]
Go to the top of the page
+Quote Post
BuffaloHelp
no avatar
More than meets the eye
******************
Group: Admin
Posts: 3,762
Joined: 23-April 05
From: Trap17 storage box
Member No.: 6,042
myCENT:49.00



Post #2 post Feb 17 2007, 06:54 AM
The javascript execCommand() apparently works only for Internet Explorer.

So perhaps a new javascript is needed that does not use execCommand().

Check this page: http://www.febooti.com/support/website-hel...-clipboard.html for allowing Firefox and Mozilla to enable to copy to the clip board. The better copy and paste script should work, by default, in IE and Opera.

The following code seems to work for all browsers

HTML
<script language="javascript" type="text/javascript">
<!--

// Copyright (C) krikkit - krikkit@gmx.net
// --> [url=http://www.krikkit.net/]http://www.krikkit.net/[/url]
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

function copy_clip(meintext)
{
if (window.clipboardData)
{

// the IE-manier
window.clipboardData.setData("Text", meintext);

// waarschijnlijk niet de beste manier om Moz/NS te detecteren;
// het is mij echter onbekend vanaf welke versie dit precies werkt:
}
else if (window.netscape)
{

// dit is belangrijk maar staat nergens duidelijk vermeld:
// you have to sign the code to enable this, or see notes below
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

// maak een interface naar het clipboard
var clip = Components.classes['@mozilla.org/widget/clipboard;1']
.createInstance(Components.interfaces.nsIClipboard);
if (!clip) return;

// maak een transferable
var trans = Components.classes['@mozilla.org/widget/transferable;1']
.createInstance(Components.interfaces.nsITransferable);
if (!trans) return;

// specificeer wat voor soort data we op willen halen; text in dit geval
trans.addDataFlavor('text/unicode');

// om de data uit de transferable te halen hebben we 2 nieuwe objecten
// nodig om het in op te slaan
var str = new Object();
var len = new Object();

var str = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);

var copytext=meintext;

str.data=copytext;

trans.setTransferData("text/unicode",str,copytext.length*2);

var clipid=Components.interfaces.nsIClipboard;

if (!clip) return false;

clip.setData(trans,null,clipid.kGlobalClipboard);

}
alert("Following info was copied to your clipboard:\n\n" + meintext);
return false;
}
//-->
</script>


Source: http://www.krikkit.net/howto_javascript_copy_clipboard.html
Go to the top of the page
+Quote Post
delivi
no avatar
Trap Grand Marshal Member
***********
Group: [HOSTED]
Posts: 1,320
Joined: 11-January 06
Member No.: 16,932
myCENT:NEGATIVE[-455.29]



Post #3 post Feb 17 2007, 06:46 PM
The following code is working in all browsers.

QUOTE
Add in the <head> of your page
CODE
<style>
.highlighttext{
background-color:yellow;
font-weight:bold;
}
</style>

<script language="Javascript">
<!--

/*
Select and Copy form element script- By Dynamicdrive.com
For full source, Terms of service, and 100s DTHML scripts
Visit http://www.dynamicdrive.com
*/

//specify whether contents should be auto copied to clipboard (memory)
//Applies only to IE 4+
//0=no, 1=yes
var copytoclip=1

function HighlightAll(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
if (document.all&&copytoclip==1){
therange=tempval.createTextRange()
therange.execCommand("Copy")
window.status="Contents highlighted and copied to clipboard!"
setTimeout("window.status=''",1800)
}
}
//-->
</script>


QUOTE
Add the code to the <BODY>

CODE
<form name="test">
<a class="highlighttext" href="java script:HighlightAll('test.select1')">Select All</a><br>
<textarea name="select1" rows=10 cols=35 >This is some text. This is some text. This is some text. This is some text.</textarea>
</form>


QUOTE
Go to the top of the page
+Quote Post
jlhaslip
no avatar
Insert Custom Title Here
*******************
Group: [MODERATOR]
Posts: 4,908
Joined: 24-July 05
From: Linux, DOS and Windows…the good, the bad and the ugly
Member No.: 9,787
Spam Patrol
myCENT:6.20



Post #4 post Feb 17 2007, 07:44 PM
Thanks.

Without trying it, will this allow for several different forms/textareas on one page?
Go to the top of the page
+Quote Post
delivi
no avatar
Trap Grand Marshal Member
***********
Group: [HOSTED]
Posts: 1,320
Joined: 11-January 06
Member No.: 16,932
myCENT:NEGATIVE[-455.29]



Post #5 post Feb 17 2007, 08:01 PM
you can use the code I've given for any number of forms/text areas in a single page.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   5 Shibbeh 16,082 20th August 2004 - 10:04 PM
Last post by: ill
No new 47 OpaQue 19,650 26th September 2009 - 06:27 PM
Last post by: krishnanz
No new   42 djleli 14,597 4th February 2005 - 10:57 AM
Last post by: alexwhin
No New Posts   9 shadowx 3,229 12th October 2009 - 07:12 PM
Last post by: manish-mohania
No New Posts   4 xmae 9,137 24th August 2006 - 03:21 PM
Last post by: juice
No new   20 campainer 14,975 5th December 2004 - 10:30 PM
Last post by: icedragn
No New Posts   7 football123213 15,572 20th August 2004 - 12:25 AM
Last post by: ill
No new   15 -prodigy- 14,132 27th February 2005 - 10:22 PM
Last post by: alexia
No New Posts   2 -Pandemonium- 12,055 22nd August 2004 - 04:25 AM
Last post by: -Pandemonium-
No New Posts   8 -Pandemonium- 9,300 25th August 2004 - 04:00 PM
Last post by: -Pandemonium-
No New Posts   5 DataHead 8,568 24th April 2006 - 01:56 AM
Last post by: BOAW
No New Posts   0 Raptrex 7,103 6th September 2004 - 11:19 PM
Last post by: Raptrex
No New Posts   11 dozen 10,440 13th September 2004 - 07:26 PM
Last post by: melkonianarg
No New Posts 0 pasten 844 6th January 2008 - 06:53 AM
Last post by: nitish
No New Posts 4 spyshow 6,541 21st September 2004 - 03:19 AM
Last post by: Spectre


 



RSS Open Discussion Time is now: 8th November 2009 - 09:25 AM

Web Hosting Powered by ComputingHost.com.