Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

execCommand('SaveAs');

21 views
Skip to first unread message

patk...@gmail.com

unread,
Oct 27, 2005, 10:11:09 AM10/27/05
to
Well I have been looking up this lovely method for the last few days.
It works in IE still, probably because IE has not changed in the last
few years, but it does not work still in Mozilla.

In the Mozilla developers doc the 'SaveAs' command is not listed, but I
have found instances in the past where developers had posted questions
about it and have apparently had it work for them.

Does anyone know if this has been removed from Mozilla's code, or am I
possibly doing this wrong?

If it has been removed is there a way to get Context Menu > This Frame
> Save Frame As... dialog to be executed?

VK

unread,
Oct 27, 2005, 11:19:48 AM10/27/05
to

Yes you can do it potentially on any Gesko based browser on any OS
platform (surrently tested on FF 1.0.7 only though) using XPConnect
interfaces.

Watch line breaks!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>filePicker</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">

<script type="text/javascript">

var priv1 = "UniversalXPConnect";
var priv2 = "UniversalFileRead";
var privilegeGranted = true;
var runtimeError = '';

function ffFileChooser() {
try {
netscape.security.PrivilegeManager.enablePrivilege(priv1);
netscape.security.PrivilegeManager.enablePrivilege(priv2);
}
catch(e) {
privilegeGranted = false;
runtimeError = "Extended privileges are not granted by user";
}
finally {
/*NOP*/
}
if (privilegeGranted) {
var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp =
Components.classes['@mozilla.org/filepicker;1'].createInstance(nsIFilePicker);
fp.init(window, 'Select a File', nsIFilePicker.modeOpen);
fp.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterAll);
var res = fp.show();
if (res == nsIFilePicker.returnOK) {
alert(fp.file.name);
}
}
}
</script>

<style type="text/css">
body { background-color: #FFFFFF}
</style>

</head>

<body>
<p onclick="ffFileChooser()">click me</p>
</body>
</html>

VK

unread,
Oct 27, 2005, 1:34:03 PM10/27/05
to


I fought with myself for several hours but the temptation is too high
:-)
So:

At my best knowledge the above posted code is the only *working* sample
of XMConnect for FireFox currently existing on the Internet.

Even samples posted by XPCOM / XPConnect Working Groups (on
mozilla.org) are not working. They contain some rather rude mistakes.
It may be due to the bad subject knowledge (? :-) or because they
wanted to avoid a wide use of it until the projects are finished (?)

Also please notice that XPConnect *doesn't need* Java installed.
netscape.security.* package (from Netscape 4) emulated right in the
core browser code.

patk...@gmail.com

unread,
Oct 27, 2005, 4:56:01 PM10/27/05
to
It took me a while to get it to work but it finally did.

First, the browser needs to be allowed to have codebase principal
support. To do this open a new tab, type in about:config. Navigate
the right colomn for "signed.applets.codebase_principal_support' and
set it to true.

Second, the code needs to be modified slightly (at least I had to).

var fp =
Components.classes['...@mozilla.org/filepicker;1'].createInstance(nsIFilePicker);


should be


Notice i removed '...' before '@mozilla.org'. Javascript console said
something or another and then I compared it to some code I found
somewhere courteous of VK's code.

http://kb.mozillazine.org/NsIFilePicker

There seems to be quite a bit of information at the site. Never knew
it was there.

In addition to a user needing to do the first step they will also need
to 'Allow' the permissions to be changed twice every time.

VK

unread,
Oct 27, 2005, 6:07:39 PM10/27/05
to

patk...@gmail.com wrote:
> First, the browser needs to be allowed to have codebase principal
> support. To do this open a new tab, type in about:config. Navigate
> the right colomn for "signed.applets.codebase_principal_support' and
> set it to true.

Don't do that if you have Sun Java plugin installed as it compromises
your security. (And definitely you cannot expect it from your site
visitors). As I mentioned before XPConnect has nothing to do with Java
code despite it uses Netscape 4.x Capabilities security scheme as well
as the mechanics and methods/properties names - but all of this is
emulated by native browser code.
The posted code is tested OK under Windows 98 SE w/o any Java installed
(neither from Sun nor from Microsoft). My
signed.applets.codebase_principal_support is set on default false.
If it fails to work as it is check if you are using the latest FireFox
release. The mine is 1.0.7 / minor 1.7.12

Naturally it should ask for signed HTML page if loaded from server (?)
but no problem on local drive. I'm still in testing.


> Second, the code needs to be modified slightly (at least I had to).
>
> var fp =
> Components.classes['...@mozilla.org/filepicker;1'].createInstance(nsIFilePicker);

Not my fault, say thanks to Google Groups spam bot protection which
modified my code :-(
I confirm it must be only "single_quote at_sign mozilla dot org"

> http://kb.mozillazine.org/NsIFilePicker
>
> There seems to be quite a bit of information at the site. Never knew
> it was there.

And you may notice that the code posted at that address is not working
due to the missing privilege request. Is it some kind of "allowance
code"? Thus if you know, you'll edit it, if you don't know it then it's
not for your usage (?)

> In addition to a user needing to do the first step they will also need
> to 'Allow' the permissions to be changed twice every time.

Unfortunately yes and I see it as XPConnect Group oops I'm going to
report. Netscape scheme implements two kinds of targets: Primitive
targets and Macro targets. The last serve as nodes for related
Primitive targets.
Say you can ask for UniversalFileRead and UniversalFileWrite (double
request using primitive targets) or UniversalFileAccess (single request
using macro target).
But in order to use XPConnect interfaces you need first request for the
newly introduced UniversalXPConnect privilege which is not included in
any macro target. You are not allowed to combine primitive targets in
new macro targets. So currently you need ask first for privilege to use
XPConnect (UniversalXPConnect) and then ask for privilege to make it
anyhow usable (say UniversaFileRead). IMHO it doesn't have too much of
sense and UniversalXPConnect should be dropped. But right now it is as
it is.

0 new messages