View Single Post
  #1 (permalink)  
Old Sep 24th, 2007, 11:33
andrewlondon andrewlondon is offline
Junior Member
Join Date: May 2006
Location: London
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to andrewlondon
Javascript Copy to clipboard Object Error

Hi, i've got this piece of javascript that lets visitors to my site either highlight a specific <textarea> (firefox) or copy to clipboard (Internet Explorer). It's working correctly on highlighting but it isn't Copying anything to the clipboard... Instead it's spitting out Object Expected errors when you click the copy to clipboard button.

I haven't touched JavaScript much but this is something i really need to get working for my site. Would somebody please be able to tell me why it isn't functioning properly in beginners speak?

Code: Select all
Head Part:
<!-- Copy & Highlight Banner1 -->
	<SCRIPT language="JavaScript">
		function banner1highlight() {
			document.Form1.banner1.select(); document.Form1.banner1.focus();
		}
		
		function banner1copy() {
			highlightmetasearch();
			textRange = document.Form1.banner1.createTextRange();
			textRange.execCommand("RemoveFormat");
			textRange.execCommand("Copy");
			alert("This text has been copied to your clipboard.");
	   }
   </SCRIPT>

Body Part:
<form enctype="multipart/form-data" name="Form1">	        
				<textarea name="banner1" rows="3" cols="70"><a href="http://www.goldenjoystick.com/refer/{ref_id}"><img src="http://www.goldenjoysticks.com/banners/banner1.gif"></a></textarea><br><br>
					<script language="JavaScript" type="text/javascript">
						if ((navigator.appName=="Microsoft Internet Explorer")&&(parseInt(navigator.appVersion)>=4)) {
						document.write('<INPUT type="button" value="  Copy To Clipboard  " onClick="banner1copy();">');
						} else {
						document.write('<INPUT type="button" value="  Highlight Text  " onClick="banner1highlight();"> *Press CTRL + C to copy this html to your clipboard.');
						}
					</script>
</form>
Reply With Quote