Web Design and Development Forums

Javascript Copy to clipboard Object Error

This is a discussion on "Javascript Copy to clipboard Object Error" within the JavaScript Forum section. This forum, and the thread "Javascript Copy to clipboard Object Error are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > JavaScript Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Sep 24th, 2007, 11:33   #1 (permalink)
Junior Member
 
Join Date: May 2006
Location: London
Posts: 33
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>
andrewlondon is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Sep 24th, 2007, 13:15   #2 (permalink)
 
Rakuli's Avatar
 
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 980
Blog Entries: 2
Re: Javascript Copy to clipboard Object Error

I've never really got involved in IE propriety commands but I have used a much more comprehensive function previously.

I can't remember the site I got it from but it's -- I have added the highlight part to the top to make the text selected in browsers that won't support this

Code: Select all
// Use this as the function in your onclick call
function allBrowserCopy{
document.Form1.banner1.select(); document.Form1.banner1.focus();
copyToClipboard(document.Form1.banner1.value);
}

function copyToClipboard(s)
{


	if( window.clipboardData && clipboardData.setData )
	{
		clipboardData.setData("Text", s);
	}
	else
	{
		// You have to sign the code to enable this or allow the action in about:config by changing
		user_pref("signed.applets.codebase_principal_support", true);
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

		var clip Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;

		// create a transferable
		var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;

		// specify the data we wish to handle. Plaintext in this case.
		trans.addDataFlavor('text/unicode');

		// To get the data from the transferable we need two new objects
		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);	   
	}
}
__________________
Rakuli

Helping you expand your epiphanies:

pen Source of pen Thoughts
Rakuli is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Call to a non object fatal error alexgeek PHP Forum 2 Feb 21st, 2008 15:34
Javascript Copy All selfAfflicted JavaScript Forum 4 Sep 7th, 2007 08:01
systex error backup copy Aaron1988 MySQL 2 Mar 4th, 2007 22:45
Copy to clipboard button helpmhost Flash & Multimedia Forum 0 Apr 22nd, 2006 09:25
Error Message when trying to manual copy records from diff DB InsouciantCoquette MSSQL & Access 1 Jan 27th, 2006 06:39



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 08:37.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59