从Web浏览器打开文件系统文件夹/目录 [英] Opening a file system folder/directory from web browser

查看:3074
本文介绍了从Web浏览器打开文件系统文件夹/目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows,Mac和Linux上将我的桌面应用程序分配给闪存驱动器上的数千个用户。我有一个HTML启动器页面,其中包含文档,安装指南,发行说明等都在闪存驱动器上的链接。我希望用户只需直接从浏览器安装,但这正是反病毒程序试图阻止(正确的)。而不是试图启动安装程序,足以找到安装程序,让用户自己采取最后一步。



是否可能导致主计算机上的文件系统管理器(Explorer,Finder等)打开包含该文件的文件夹并高亮显示?我认为这将需要JavaScript,它可能必须是不同的Windows,Mac和Linux。此外,在大多数浏览器(IE,FF,Chrome,Safari,Opera)中也可以使用。



这是一个类似的难度级别,用于解决Fermat的最后定理?

感谢

解决方案

此JS代码应该适用于Windows上的IE和Firefox因为页面是从本地文件系统加载的。你需要在Linux / OSX上测试。我不知道如何处理chrome / safari / opera。

 函数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);
}
}
}

当然,以签署.js文件,以使其工作。有关详情,请参阅此处: http://www.mozilla.org/ projects / security / components / signed-scripts.html


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

这篇关于从Web浏览器打开文件系统文件夹/目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆