473,326 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Doesn't work on Firefox

I found the following script to copy text to the client clipboard but
it is not working in Firefox (works fine in IE 6). Can anyone suggest
what I need to change?

=================================================
function copy_clip(mytext){
if (window.clipboardData)
{
// IE
window.clipboardData.setData("Text", mytext);
// Netscape
}
else if (window.netscape)
{

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.nsITransfera ble);
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.nsISupportsS tring);

var copytext=mytext;
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("Following info was copied to your clipboard:\n\n" + mytext);
return false;
}
==========================================

Jul 23 '05 #1
10 17541
wa***@wengert.org wrote:
I found the following script to copy text to the client clipboard but
it is not working in Firefox (works fine in IE 6). Can anyone suggest
what I need to change?

=================================================
function copy_clip(mytext){
if (window.clipboardData)


Try this in non-IE browsers:

alert( window.clipboardData )
You will most likely get 'undefined'. Firefox et al don't support
copying to the clipboard.
[...]
--
Rob
Jul 23 '05 #2
Thanks. That is exactly what happened.

So, I need to detect those browsers and disable the clipboard options?

Wayne

"RobG" <rg***@iinet.net.auau> wrote in message
news:42**********************@per-qv1-newsreader-01.iinet.net.au...
wa***@wengert.org wrote:
I found the following script to copy text to the client clipboard but
it is not working in Firefox (works fine in IE 6). Can anyone suggest
what I need to change?

=================================================
function copy_clip(mytext){
if (window.clipboardData)


Try this in non-IE browsers:

alert( window.clipboardData )
You will most likely get 'undefined'. Firefox et al don't support copying
to the clipboard.
[...]
--
Rob

Jul 23 '05 #3
For Firefox, there is an alternative.

Take a look at

http://www.xulplanet.com/tutorials/xultu/clipboard.html

Jul 23 '05 #4
Sorry, forget my answer. I note you have got this covered in your code
above.

I would like to respectfully disagree with RobG.

I think that Firefox does support clipboard operations (as did
Mozilla), through XPConnect as you note.

Your "if" statements should also discount other browsers, as you
correctly do this by means of a "feature" test.

I would think that your problem lies somewhere in your XPConnect code
stated above. I have not had chance to look closely, but XUL Planet is
a good source of information.

Jul 23 '05 #5
Thanks for the response. The sample script I included supposidly uses that
approach but obviously I missed something.

Wayne

"Baconbutty" <ju****@baconbutty.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
For Firefox, there is an alternative.

Take a look at

http://www.xulplanet.com/tutorials/xultu/clipboard.html

Jul 23 '05 #6
Thanks.... I'll keep looking.

Wayne

"Baconbutty" <ju****@baconbutty.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Sorry, forget my answer. I note you have got this covered in your code
above.

I would like to respectfully disagree with RobG.

I think that Firefox does support clipboard operations (as did
Mozilla), through XPConnect as you note.

Your "if" statements should also discount other browsers, as you
correctly do this by means of a "feature" test.

I would think that your problem lies somewhere in your XPConnect code
stated above. I have not had chance to look closely, but XUL Planet is
a good source of information.

Jul 23 '05 #7
I re-coded the function to match the site you referenced (see below) and I
see the alert("copytext set") alert
but not the alert("Just tried to set str")? It appears that the step to set
the value of "str" causes the function to terminate?
I don't gey any error messages?

Any thoughts?

Wayne

==================================================
function copy_clip(mytext){
if (window.clipboardData)
{
// IE
window.clipboardData.setData("Text", mytext);
// Netscape
}
else if (window.netscape)
{
//
netscape.security.PrivilegeManager.enablePrivilege ('UniversalXPConnect');
var copytext=mytext;
alert("copytext set")
var str = Components.classes["@mozilla.org/supports-string;1"].
createInstance(Components.interfaces.nsISupportsSt ring);
alert("Just tried to set str")
if (!str) return false;
str.data = copytext;
alert("Just set str.data")
var trans = Components.classes["@mozilla.org/widget/transferable;1"].
createInstance(Components.interfaces.nsITransferab le);
if (!trans) return false;
alert("Just set trans")
trans.addDataFlavor("text/unicode");
trans.setTransferData("text/unicode",str,copytext.length * 2);

var clipid = Components.interfaces.nsIClipboard;
var clip =
Components.classes["@mozilla.org/widget/clipboard;1"].getService(clipid);
if (!clip) return false;

clip.setData(trans,null,clipid.kGlobalClipboard);
}
alert("Following info was copied to your clipboard:\n\n" + mytext);
return false
}
================================================== =
"Baconbutty" <ju****@baconbutty.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Sorry, forget my answer. I note you have got this covered in your code
above.

I would like to respectfully disagree with RobG.

I think that Firefox does support clipboard operations (as did
Mozilla), through XPConnect as you note.

Your "if" statements should also discount other browsers, as you
correctly do this by means of a "feature" test.

I would think that your problem lies somewhere in your XPConnect code
stated above. I have not had chance to look closely, but XUL Planet is
a good source of information.

Jul 23 '05 #8
Wayne W wrote:
Thanks.... I'll keep looking.

Please don't top-post. Although that is the default behaviour of
Outlook Express, but it's not the preferred layout of this group.

Here are a couple of links regarding using the clipboard and Mozilla:

<URL:http://www.infogears.com/cgi-bin/infogears/mozilla_firefox_copy_paste.html>

<URL:http://www.mozilla.org/projects/security/components/per-file.html>

Users can allow access to the clipboard on a per-site basis, however it
requires modification of user preferences that are likely beyond the
average web surfer. As a result you should expect that, in a general web
context, clipboard support is not available.

If your usage is for an intranet, and you can control a users' settings,
then maybe you can make it work reliably. This newsgroup is intended to
focus on JavaScript for the web, hence responses tend to bent in that
direction.
Wayne

"Baconbutty" <ju****@baconbutty.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Sorry, forget my answer. I note you have got this covered in your code
above.

I would like to respectfully disagree with RobG.
Yes, I was a bit dismissive. :-x

Mozilla does support the clipboard, but only through specific user
actions to allow access to it. Page authors should not expect clipboard
support to be available, and therefore should probably not attempt to
use it. The links above show how to enable it - I don't think your
average user is going to be able to do it even if you can convince them to.

Support within an intranet may be able to be made more reliable.

I think that Firefox does support clipboard operations (as did
Mozilla), through XPConnect as you note.

Your "if" statements should also discount other browsers, as you
correctly do this by means of a "feature" test.


The feature tests are insufficient - testing for 'window.netscape' does
not ensure that PrivilegeManager.enablePrivilege is supported, or that
the user will allow the privileges to be modified.

That call should be inside a try..catch block in case the user refuses
to change their privileges, or you can let them deal with the message
starting:

"A script from /your_domain/ is requesting enhanced abilities that
are UNSAFE and could be used to compromise your machine or data:"

[...]

--
Rob
Jul 23 '05 #9
Rob;

Thanks for the very educational response.

I'm not sure what "top posting" is nor how to prevent it?

I'll do some more reading and re-think my general approach here. Too bad
because, in my option, saving the user from having to select and the "copy"
seems like a good thing. It is so easy to accomplish for IE.

Oh well

Wayne

"RobG" <rg***@iinet.net.auau> wrote in message
news:kR***************@news.optus.net.au...
Wayne W wrote:
Thanks.... I'll keep looking.


Please don't top-post. Although that is the default behaviour of Outlook
Express, but it's not the preferred layout of this group.

Here are a couple of links regarding using the clipboard and Mozilla:

<URL:http://www.infogears.com/cgi-bin/infogears/mozilla_firefox_copy_paste.html>

<URL:http://www.mozilla.org/projects/security/components/per-file.html>

Users can allow access to the clipboard on a per-site basis, however it
requires modification of user preferences that are likely beyond the
average web surfer. As a result you should expect that, in a general web
context, clipboard support is not available.

If your usage is for an intranet, and you can control a users' settings,
then maybe you can make it work reliably. This newsgroup is intended to
focus on JavaScript for the web, hence responses tend to bent in that
direction.
Wayne

"Baconbutty" <ju****@baconbutty.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Sorry, forget my answer. I note you have got this covered in your code
above.

I would like to respectfully disagree with RobG.
Yes, I was a bit dismissive. :-x

Mozilla does support the clipboard, but only through specific user actions
to allow access to it. Page authors should not expect clipboard support
to be available, and therefore should probably not attempt to use it. The
links above show how to enable it - I don't think your average user is
going to be able to do it even if you can convince them to.

Support within an intranet may be able to be made more reliable.

I think that Firefox does support clipboard operations (as did
Mozilla), through XPConnect as you note.

Your "if" statements should also discount other browsers, as you
correctly do this by means of a "feature" test.


The feature tests are insufficient - testing for 'window.netscape' does
not ensure that PrivilegeManager.enablePrivilege is supported, or that the
user will allow the privileges to be modified.

That call should be inside a try..catch block in case the user refuses to
change their privileges, or you can let them deal with the message
starting:

"A script from /your_domain/ is requesting enhanced abilities that
are UNSAFE and could be used to compromise your machine or data:"

[...]

--
Rob

Jul 23 '05 #10
Wayne W wrote:
[...]
I'm not sure what "top posting" is nor how to prevent it?
a message whith top posting looks like this:

| Because it messes up the flow of reading.
| > How come?
| > > I prefer to reply inline.
| > > > What do you do instead?
| > > > > No.
| > > > > > Do you like top-posting?

IOW, readable like black ink on black paper.
I'll do some more reading and re-think my general approach here. Too bad
because, in my option, saving the user from having to select and the "copy"
seems like a good thing. It is so easy to accomplish for IE.

Oh well

[...]

Inline and bottom posting are the preferred Newsgroup styles.

You can prevent top posting by trimming the quoted text to the essential,
reply inline (just after a section you want to comment on, answer or reply to)
and/or at the end (or bottom) of the quoted (and hopefully now trimmed) text
like I am doing right now.

http://en.wikipedia.org/wiki/Top-posting

Jul 23 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Paxton | last post by:
I created an html email containing a form whose method is POST. The form is posted to an asp page for processing, but no values are retrieved. So I response.write all the Request.Form fields, and...
3
by: milkyway | last post by:
Hello, I am working with an old Java Script code and have found the following but after putting in alerts I have found that insertRow doesn't work. What is the problem? TIA function...
6
by: Cliff R. | last post by:
Hi, I use a handy little Javascript Flash detection script on a number of sites (copied below). Usually works great, but I just started trying Firefox and it's not working. A few browsers are...
3
by: niconedz | last post by:
Hi The following code works fine in IE but not Firefox. It's a little script that zooms an image and resizes the window to fit. Can anybody tell me what's wrong? Thanks Nico == btw.....
4
by: Joe | last post by:
Hello, I have created a login page using dotnet. I am using requiredFieldValidator and noticed that the code works fine in IE but not in Netscape, Opera, Mozilla, Firefox, etc. For example...
4
by: bbp | last post by:
Hello, In an ASPX page I have a "Quit" button which make a simple redirect in code-behind. This button doesn't work no more since (I think) I moved from the framework 1.0 to 1.1 and it doesn't...
21
by: briggs | last post by:
<html> <head> <script> /* AddChild */ function ac() { var c; var p = document.getElementById("p"); for (var i = 0; i < 5; i++) { c = document.createElement("DIV"); // Create 'div' element.
23
by: wylbur37 | last post by:
I'm running an Apache server on my own computer (Windows XP Pro). I wrote a simple PHP script (called test3.php) that I'm running by putting the following URL in the address bar of the browser...
2
bilibytes
by: bilibytes | last post by:
Hi, i have been creating an ajax aplication on my website and it worked as i expected it to work on Safari and Firefox, until i upgraded to Firefox 3. It doesn't work either on windows. the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.