admin管理员组文章数量:1335386
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 puter 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
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 puter 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
Share Improve this question asked Nov 18, 2010 at 18:04 Eric CloningerEric Cloninger 2,2602 gold badges21 silver badges26 bronze badges2 Answers
Reset to default 3Nope. 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.
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(mand, mandParam)
{
if (isIE()) {
try {
activexShell = new ActiveXObject("Shell.Application");
activexShell.ShellExecute(mand, mandParam, "", "open", "1");
exit();
} catch (e) {
alert("exception " + e.name + ': ' + e.message);
}
}
else {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var FileFactory = new Components.Constructor("@mozilla/file/local;1","nsILocalFile","initWithPath");
var program = new FileFactory(mand);
var process = Components.classes["@mozilla/process/util;1"].createInstance(Components.interfaces. nsIProcess);
process.init(program);
process.run(false, mandArray, mandParam.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/projects/security/ponents/signed-scripts.html
本文标签: javascriptOpening a file system folderdirectory from web browserStack Overflow
版权声明:本文标题:javascript - Opening a file system folderdirectory from web browser - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742385520a2464953.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论