pa*******@gmail.com wrote:
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?
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>