hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : JS clipboard script in Firefox
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

JS clipboard script in Firefox

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 02-13-2006, 07:25 PM
PlanetWebHost PlanetWebHost is offline
WHT Addict
 
Join Date: Oct 2001
Location: Mountain Home Arkansas
Posts: 131

JS clipboard script in Firefox


Hi,

I have a JS function that will highlight a <div> tag and copy it to the users clipboard, but unfortunaly, it's using JS functionality that is only available in IE.

Does anyone have any ideas on how I can get this working a little more cross-browser?


The full discussion is here: http://phpscriptlets.com/viewtopic.php?t=9
HTML Code:
<SCRIPT>

function SelectCopy(div_id) {
   if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion >= "4.0"){
      for (i=0; i<document.all.length; i++) {
          document.all(i).unselectable = "on"
      }
      document.getElementById(div_id).unselectable = "off";
      document.getElementById(div_id).focus();
   
      document.execCommand('SelectAll');
      document.execCommand('Copy');
   
      for (i=0; i<document.all.length; i++) {
         document.all(i).unselectable = "off"
      }
   }else{
      alert("Sorry, this only works for InternetExploder")
   }
}

</SCRIPT>
<BODY>
<a href="#" title="Copy to Clipboard" onClick="SelectCopy('EDITBOX')">Copy To Clipboard</a> 

<br />
<DIV id="EDITBOX" contenteditable="true" style="height:230px; padding:3; border:solid 1; overflow:auto; background-color:#FFFFFF; font-family:times new roman; font-size:12pt">
<b>This is BOLD</b> - <i>This is italic</i> - <font color="red">This is colored red</font>
</DIV>



<a href="#" title="Copy to Clipboard" onClick="SelectCopy('EDITBOX2')">Copy To Clipboard</a> 

<br />
<DIV id="EDITBOX2" contenteditable="true" style="height:230px; padding:3; border:solid 1; overflow:auto; background-color:#FFFFFF; font-family:times new roman; font-size:12pt">
<b>This is another section of text</b>
</DIV>

<textarea style="width:300px;height:60px;"></textarea>
</BODY>

__________________
rocket science is more fun when you accually have rockets!

Reply With Quote


Sponsored Links
  #2  
Old 02-15-2006, 01:18 PM
cyx cyx is offline
Newbie
 
Join Date: Sep 2003
Posts: 27
Thumbs up Firefox prevents clipboard control on default

Firefox prevents clipboard control on default, and this is for security reasons. Picture a user always using the clipboard to copy/paste his bank password, or something like that, ANY website run on Internet Explorer can "grab" his clipboard contents, and save it, leaving the user clueless to what just happend, and he'll never know better.

That's one of the best reasons of using Firefox. More secured than IE.
There is a way to disable the clipboard disabled features, and even run a list of allowed sites.

Here is the script for Firefox:

Code:
		<script language="javascript">
			//To allow paste function to work in firefox you must:
			//write in url about:config
			//and change signed.applets.codebase_principal_support = true

			function init()
			{
				try
				{
					window.clipboard = new Clipboard();
				}
				catch (e)
				{
					alert("If you are using firefox please do the following :\n 1. Write in your url box : 'about:config'\n2. Change signed.applets.codebase_principal_support = true\n")
				}
			}

			// Must init the clipboard
			window.onload = init;	

                        // Function to return the data in clipboard
			function getClipboardContents()
			{
				return window.clipboard.paste();
			}
            </script>

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Mozilla Firefox 23 Will Block Mix SSL Content by Default Web Hosting News 2013-04-12 11:39:07
Pingdom Talks Top Web Hosting Cities and Countries Web Hosting News 2013-03-27 18:49:54
Mega Firefox Extension Speeds Up Downloads, Removes File Size Limits Web Hosting News 2013-02-11 11:43:22
Control Panel cPanel Launches New Apache Configuration Script Web Hosting News 2011-12-28 19:41:39
Web Host JaguarPC Adds Auto-Installer Softaculous to Hosting Plans Web Hosting News 2011-07-27 18:55:46


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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 Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?