Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> One Click To Copy Script, In IE6 it works, but not FF2
jlhaslip
post Feb 17 2007, 06:30 AM
Post #1


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 4,005
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



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.

CODE
<!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>
Go to the top of the page
 
+Quote Post
BuffaloHELP
post Feb 17 2007, 06:54 AM
Post #2


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

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



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
post Feb 17 2007, 06:46 PM
Post #3


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

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



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
post Feb 17 2007, 07:44 PM
Post #4


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 4,005
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



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
post Feb 17 2007, 08:01 PM
Post #5


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

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



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

Topics Topics
  1. Auto Run Java Program(11)
  2. Could Someone Make A Php Script For Me?(3)
  3. *** Click Here To Get Your Free Hosting ***(1)
  4. Copy Protect Cd(9)
  5. Web Surfing- Script Needed(2)
  6. Delay X Seconds In Flash(1)
  7. Verifying Email Addresses(9)
  8. What Free Advertising Program Do You Like?(7)
  9. Watermark Your Image With Simple Php Script(35)
  10. Assist Breast Cancer Research(5)
  11. Is There Any Ad Click Service For Under 18?(8)
  12. Make Money Clicking On Links(8)
  13. Help With Installing Sims 2(9)
  14. Background Image Swap Script(15)
  15. Php Downloads Script(4)
  1. Forget About 0.01 Per Click, Get 0.06 Per Search!(15)
  2. Login Script For Vbulletin.(9)
  3. Do Ouija Board Works(7)
  4. A Game In The Works, Still Need A Name(4)
  5. Guessing Php Script(2)
  6. Phpizabi Social Network Script(1)
  7. Need Help For Seo And Internet Marketing Works!(3)
  8. Php Guest Online Script(3)
  9. Ptc Sites (pay To Click)(0)
  10. How To Make Php Newsletter Script(3)
  11. Browser Compatibility Problem With Firefox - Javascript + Css(3)
  12. Seeking Help With Javascript(1)
  13. Locking A Folder With No Software At All!(4)


 



- Lo-Fi Version Time is now: 8th September 2008 - 02:24 PM