SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Jan 24, 2007, 08:21 #1
- Join Date
- Jan 2007
- Posts
- 1
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Definative Answer: Mozilla and the Clipboard
I've inherited this webpage where I work that has a non-functional Copy to Clipboard button. Basically the idea is you click this button, and a variable full of data is passed to a JavaScript function which is supposed to then copy it to the OS clipboard.
I've found a script that claims to work, and a couple minor variations thereof, but I can't get it to work. I've seen a lot of forum posts about it, but in none of the threads does anyone really give a definitive answer as to whether it's proven to work.
Below is the script. It works for IE, fails for Firefox. The URL it was basically taken from is http://www.krikkit.net/howto_javascr...clipboard.html. I'm really just looking for a final yes or no answer as to whether Firefox will do clipboard work without a user having to tweak their JavaScript security settings.
Code:function copy_clip(meintext) { if (window.clipboardData) { window.clipboardData.setData("Text", meintext); } else { netscape.security.PrivilegeManager.enablePrivilege ('UniversalXPConnect'); var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard ); if (!clip) return; var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable); if (!trans) return; trans.addDataFlavor('text/unicode'); 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); ) alert("Clipboard Copy has been succesful"); return false; }
-
Jan 24, 2007, 09:00 #2
- Join Date
- Jan 2002
- Location
- N 44° 56.537' W 123° 3.683'
- Posts
- 1,127
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The window.clipboardData object is only supported by IE. Entering this in the location bar of a JavaScript enabled browser will pop an alert that indicates whether clipboardData is supported:
javascript:alert(window.clipboardData?true:false);
According to Microsoft, the object has been available since v. 5 of IE; http://msdn.microsoft.com/workshop/a...pboarddata.asp
-
Jan 24, 2007, 09:06 #3
- Join Date
- Dec 2006
- Posts
- 182
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Use that function for browsers that support window.clipboardData, then if it does not, just have it create and dump the data to a textfield with instructions to copy manually.
-
Jan 24, 2007, 15:55 #4
- Join Date
- Dec 2006
- Location
- Prague
- Posts
- 210
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
When you are using Signed Scripts in Mozilla they has to be allowed by user. For copying try to search this keyword UniversalSystemClipboardAccess. But maybe quickest way could be studying some xpi code. This one use clipboard https://addons.mozilla.org/firefox/491/ download it instead of install, extract somewhere (with some extractor I recomend 7zip) , there will be probably few file inside, one is called chrome. Open it and inside will be some file with suffix .jar, extract this one and inside will be content, locale =languages and skin. Open content and study all js inside this file. Inside is this http://www.expressnewsindia.com/site...0Clipboard.htm
. I see now it has nothing with js, anyway I leave this comment here, because there is a lot of interesting script inside FF add-ons, and it could help someone to study them.
-
Jan 24, 2007, 19:23 #5
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
IE is the only browser that only runs on Windows. All the other browsers also run on a variety of other platforms and not all of those platforms even have a clipboard to copy to.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
Jan 24, 2007, 19:56 #6
- Join Date
- Jan 2002
- Location
- N 44° 56.537' W 123° 3.683'
- Posts
- 1,127
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
In case it got lost here, the window.clipboardData object is contained at the browser level and is domain restricted; it is not the system clipboard.
As an aside, IE can be had to run with Wine quite nicely, through version 6. A useful script for installing versions of IE on most desktop Linux can be found at: http://www.tatanka.com.br/ies4linux/page/Main_Page
IE 7 on Linux is still a work in progress, though some are reporting good success.
Bookmarks