I distribute my desktop application on flash drives to thousands of users on Windows, Mac, and Linux. I have a HTML starter page that has links to the documentation, install guide, release notes, etc. which are all on the flash drive. I would love for the user to just install directly from the browser, but that's exactly what anti-virus programs are trying to prevent (and rightly so). Instead of trying to launch the installer, it's enough to locate the installer and let the user take the last step by themselves.
Is it possible to cause the file system manager (Explorer, Finder, etc.) on the host computer to open the folder containing the file and highlight it? I assume this would require JavaScript and it would probably have to be different for Windows, Mac, and Linux. Plus, work in most browsers (IE, FF, Chrome, Safari, Opera).
Is this on a similar difficulty scale to solving Fermat's Last Theorem?
Thanks
This JS code should work for IE and Firefox on Windows as long as the page was loaded from your local filesystem. You would need to test this on Linux/OSX. I don't know how you would approach chrome/safari/opera.
function execute(command, commandParam)
{
if (isIE()) {
try {
activexShell = new ActiveXObject("Shell.Application");
activexShell.ShellExecute(command, commandParam, "", "open", "1");
exit();
} catch (e) {
alert("exception " + e.name + ': ' + e.message);
}
}
else {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var FileFactory = new Components.Constructor("@mozilla.org/file/local;1","nsILocalFile","initWithPath");
var program = new FileFactory(command);
var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces. nsIProcess);
process.init(program);
process.run(false, commandArray, commandParam.split(" ").length - 1, {});
exit();
} catch (e) {
alert("exception " + e.name + ': ' + e.message);
}
}
}
Of course, you may need to sign the .js file in order to get it to work. For more info, see here: http://www.mozilla.org/projects/security/components/signed-scripts.html
Nope. Browsers (or most of them*) prevent this sort of behavior. They have a wall between your actual file system and the content that the Web serves you. Only the HTML input control breaks this, and they have quite a bit of protection around that, too.
*- You can use an IE ActiveX control, but that is IE-only.
来源:https://stackoverflow.com/questions/4218018/opening-a-file-system-folder-directory-from-web-browser