从网页中在finder/explorer中打开一个文件夹? [英] Open a folder in finder/explorer from a webpage?
问题描述
如果我有文件系统路径,是否可以在Explorer(在Windows上)或Finder(在OS X上)中打开一个窗口,显示该路径指向的文件夹?
If I have a file system path can I open a window in Explorer (on windows) or in Finder (on OS X) displaying the folder that the path leads to?
Cookie指向跨平台和/或无插件的答案.
Cookie points for answers that are cross-platform and/or plugin-less.
推荐答案
您需要能够从浏览器运行新进程.有几种方法可以做到这一点.我将展示JNLP的实现方法.
You need to be able to run a new process from a browser. There are a few ways to do this. I'll show the JNLP way to do this.
创建一个jnlp文件,如下所示:
Create a jnlp file as follows:
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="http://example/" href="jnlpTest.jnlp">
<information>
<title>Some Title</title>
<vendor>Some Vendor</vendor>
<homepage href="http://example/" />
<description>Some Description</description>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.6+" />
<jar href="jnlpTest.jar" />
</resources>
<application-desc main-class="MainClass" />
</jnlp>
根据以下内容创建一个jnlpTest.jar:
Create a jnlpTest.jar from the following:
public class MainClass {
public static void main(String args[]) {
Runtime rt = Runtime.getRuntime();
try {
//TODO - different exec for Mac
rt.exec("explorer.exe");
} catch (IOException e) {
//exception
}
}
}
有清单:
Manifest-Version: 1.0
Main-Class: MainClass
签名您的JNLP jar:
Sign your JNLP jar:
keytool -genkey -keystore testKeys -alias jdc
jarsigner -keystore testKeys jnlpTest.jar jdc
将jar和jnlp文件都放置在Web服务器上.确保将哑剧类型JNLP用作application/x-java-jnlp-file
.
place both the jar and jnlp file on a web server. Make sure the mime type JNLP is served as application/x-java-jnlp-file
.
制作JNLP的参考: http://java.dzone. com/articles/java-web-start-jnlp-hello
Reference for making a JNLP: http://java.dzone.com/articles/java-web-start-jnlp-hello
现在,当用户单击您的jnlp链接时,他们将下载jar,并询问是否可以运行.运行它将导致浏览器窗口打开.我知道这不是最好的解决方案,但是任何解决方案都需要征求用户许可才能在其计算机上执行代码.
Now when a user clicks your jnlp link they will download the jar and be asked if it is ok to run. Running it will cause the explorer window to open. I know it's not the best solution, but any solution will require asking the users permission to execute code on their machine.
这篇关于从网页中在finder/explorer中打开一个文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!