Jump to content
xisto Community
jlhaslip

One Click To Copy Script In IE6 it works, but not FF2

Recommended Posts

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.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://forums.xisto.com/no_longer_exists/ 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>

Share this post


Link to post
Share on other sites

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://forums.xisto.com/no_longer_exists/ 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

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

// Copyright (C) krikkit - krikkit@gmx.net
// --> [url=https://www.haider.li/;
//
// 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://forums.xisto.com/no_longer_exists/

Share this post


Link to post
Share on other sites

The following code is working in all browsers.


Add in the <head> of your page



<style>.highlighttext{background-color:yellow;font-weight:bold;}</style><script language="Javascript"><!--/*Select and Copy form element script- By Dynamicdrive.comFor full source, Terms of service, and 100s DTHML scriptsVisit dynamicdrive.com/
specify whether contents should be auto copied to clipboard (memory)//Applies only to IE 4+//0=no, 1=yesvar copytoclip=1function 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>


Add the code to the <BODY>



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



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.