Print Page | Close Window

JS: Copying a text to the clipboard.

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=9983
Printed Date: 31 March 2026 at 4:54pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: JS: Copying a text to the clipboard.
Posted By: Mc Brain
Subject: JS: Copying a text to the clipboard.
Date Posted: 13 April 2004 at 2:03pm

I want to add a javascript function to copy a specific text to the clipboard. I found this code:

<script language="javascript">
function toClipboard(){
  var text="http://www.FindYourDesire/findyourdesire/profile.php?u n=Neo";
  var copyText=text.createTextRange();
 
  return confirm("Do you want to copy the link
http://www.findyourdesire/findyourdesire/profile.php?un=Neo - http://www.FindYourDesire/findyourd...file.php?un=Neo to your clipboard?
(this only works for M$IE");
  copyText.execCommand("Copy");
  alert("If using M$IE, then you have just copied the link,
http://www.findyourdesire/findyourdesire/profile.php?un=Neo - http://www.FindYourDesire/findyourd...file.php?un=Neo to your clipboard.");
}
</script>

and changed it a little to what I need:

<script language="javascript">
function toClipboard(text){
  var copyText=text.createTextRange();

  copyText.execCommand("Copy");
}
</script>

Unfortunately, this doesn't work (the bold line raises the following error:

---------------------------
Error
---------------------------
A Runtime Error has occurred.
Do you wish to Debug?

Line: 3000
Error: Object doesn't support this property or method
---------------------------
Yes   No  
---------------------------

Can anyone give me a hint?




Replies:
Posted By: Mc Brain
Date Posted: 13 April 2004 at 2:33pm
Nevermind... I got it already.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net