Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: copy to clipboard


Message #1 by "Alex Shiell, ITS, EB, SE" <alex.shiell@s...> on Thu, 4 Jul 2002 15:40:15 +0100
Thats because thats the only thing you have on that page is the row... if
you put more rows in you'll see that they all get copied ;-)

-----Original Message-----
From: Joe Fawcett [mailto:joefawcett@h...]
Sent: 04 July 2002 16:26
To: javascript
Subject: [javascript] Re: copy to clipboard


Works for me...

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Copy row</title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/jscript">
  function doRowCopy(oRow)
  {
    var r = document.body.createTextRange();
    alert(oRow.innerText);
    r.findText(oRow.innerText);
    r.select();
    r.execCommand("copy");
  }
</script>
</head>

<body bgcolor="#FFFFFF">
<table id="tblMain" border="1" cols="1">
<tr><td>Hello, world</td></tr>
</table>
<div>More stuff here</div>
<input type="button" value="Copy row" onclick="doRowCopy(tblMain.rows[0])">
</body>
</html>

Joe


>From: "Alex Shiell, ITS, EB, SE" <alex.shiell@s...>
>Reply-To: "javascript" <javascript@p...>
>To: "javascript" <javascript@p...>
>Subject: [javascript] copy to clipboard
>Date: Thu, 4 Jul 2002 15:40:15 +0100
>
>I would like to copy the selected row of a table to the clipboard.
>
>As far as my understanding goes, this code should do it:
>
>var r = document.body.createTextRange();
>r.findText(oRow.innerText);
>r.select();
>r.execCommand("copy");
>
>But it always selects and copies the entire page.
>
>(if I alert oRow.innerText it does show me the text I want to copy)
>
>Does anyone know what I'm doing wrong?
>
>________________________________________________________________________
>Scottish Enterprise Network
>http://www.scottish-enterprise.com
>
>Headquarters Address & Contact Numbers
>
>150 Broomielaw
>5 Atlantic Quay
>Glasgow
>G2 8LU.
>Tel:  +44 (0) 141 248 2700.
>Fax:  +44 (0)141 221 3217
>
>  This message is sent in confidence for the addressee only.
>It may contain legally privileged information. The contents are not to
>be disclosed to anyone other than the addressee. Unauthorised recipients
>are requested to preserve this confidentiality and to advise the sender
>immediately of any error in transmission.
>
>
>
>
>---
>
>Improve your web design skills with these new books from Glasshaus.
>
>Usable Web Menus
>http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
>r-20
>Constructing Accessible Web Sites
>http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
>r-20
>Practical JavaScript for the Usable Web
>http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
>r-20




_________________________________________________________________
Join the world's largest e-mail service with MSN Hotmail. 
http://www.hotmail.com



---

Improve your web design skills with these new books from Glasshaus.

Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20

________________________________________________________________________
Scottish Enterprise Network
http://www.scottish-enterprise.com

Headquarters Address & Contact Numbers

150 Broomielaw
5 Atlantic Quay
Glasgow
G2 8LU.
Tel:  +44 (0) 141 248 2700.
Fax:  +44 (0)141 221 3217

 This message is sent in confidence for the addressee only.
It may contain legally privileged information. The contents are not to
be disclosed to anyone other than the addressee. Unauthorised recipients
are requested to preserve this confidentiality and to advise the sender
immediately of any error in transmission.



  Return to Index