如何通过Firefox和Chrome中网站上的链接打开文件夹? [英] How do you open a file folder through a link on website in Firefox and Chrome?

查看:259
本文介绍了如何通过Firefox和Chrome中网站上的链接打开文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个Web应用程序,该应用程序需要具有一个链接,该链接可从文件服务器打开文档文件夹。该文件夹可以在新的浏览器标签或新窗口中打开,也可以使用计算机的默认文件浏览器程序(即Windows资源管理器)打开。这个javascript应该可以解决问题:

I'm working on a web application that needs to have a link which opens a documents folder from a file server. The folder can be opened either in a new browser tab or new window, or using the computer's default file browser program (i.e. Windows Explorer). This javascript should do the trick:

window.open('file://////fileserver.companyname/public/Documents/', '_blank);

,并且该html也应该起作用:

and this html should also work:

< a href = file://///fileserver.companyname/public/Documents/>打开文档< / a>

,但它们都只能在Internet Explorer中使用,并且我们的用户始终使用Firefox和Chrome。显然,当从 http://网站调用该请求时,Firefox和Chrome的默认安全设置不允许您打开 file://。

but these both only work in Internet Explorer, and our users always use Firefox and Chrome. Apparently the default security settings for Firefox and Chrome don't let you open a "file://" when the request is called from an "http://" website.

我已经看到了对该页面的一些引用:到本地页面的链接不起作用描述了为什么无法使用Firefox打开网页中的文件,并提供了一些解决方法。不幸的是,它仅提供两个选项:在每个浏览器实例上安装插件,或为每个浏览器实例创建用户首选项文件。这些选项都不可接受,因为我们有太多用户。我工作的公司不愿意对需要访问此链接的每台计算机应用任何内容。除此之外,无论如何我都尝试了插件和首选项文件,唯一对我有用的是IE Tab插件。我认为LocalLinks不起作用的原因是因为我试图打开一个文件夹而不是一个文件。

I've seen several references to this page: Links to local pages do not work which describes why you can't open files from webpages using Firefox and offers a few workarounds. Unfortunately, it only offers two options: install a plug-in on each browser instance, or create a user preferences file for each browser instance. Neither of these options are acceptable because we have too many users. The company I work for is not willing to apply anything to each machine which needs to access this link. Aside from that, I tried both plug-ins and the preferences file anyway, and the only one that worked for me was the IE Tab plug-in. I think the reason LocalLinks didn't work is because I'm trying to open a folder, not a file.

此stackoverflow问题描述了Chrome的类似选项: Google Chrome浏览器可以打开本地链接吗?但同样,LocalLinks插件没有

This stackoverflow question described similar options for Chrome: Can Google Chrome open local links? but again, the LocalLinks plug-in didn't work for me and plug-ins aren't acceptable anyway.

我还找到了一个网站,建议使用命令行参数在Chrome中打开文件( http://www.askyb.com/chrome/open-local- file-in-google-chrome / )和一个显示如何自动应用参数的代码( https://askubuntu.com/questions/160245/making-google-chrome-option-allow-file-access-from-files-permanent ),但如果我没看错的话l涉及对访问我们网站的每台计算机进行更改。

I also found a website that suggested to use a command line argument top open files in Chrome (http://www.askyb.com/chrome/open-local-file-in-google-chrome/) and one that showed how to apply the argument automatically (https://askubuntu.com/questions/160245/making-google-chrome-option-allow-file-access-from-files-permanent), but if I read it correctly it still involves applying changes to every computer accessing our website.

有没有任何方法来打开文件夹 Firefox和Chrome 都完全以编程方式 ,即在我的Web应用程序C#或Javascript代码中,而无需安装插件或向单个计算机添加首选项文件?我无法更改任何这些业务需求。

Is there any way to open a file folder in both Firefox and Chrome entirely programmatically i.e. within my web application C# or Javascript code without installing a plug-in or adding a preferences file to individual computers? I cannot alter any of these business requirements.

Sidenote :我们将C#与MVC 4结合使用。我希望使用C#中的Controller Action打开文件夹(因为我想(例如,如果尚不存在,则在打开之前先创建该文件夹),但是可以接受客户端上的javascript或html。对于Internet Explorer,我可以通过将其包装在MVC C#控制器内置的JavaScript(...)函数中,在C#代码中创建该javascript。在Firefox和Chrome中测试IE Tabs时,我必须将其定义为href链接,而不是打开窗口的功能,否则IE Tabs不会将其识别为链接。但这都不是满足我们业务需求的可接受的解决方法。

Sidenote: We are using C# with MVC 4. I would prefer to open the folder using a Controller Action in C# (because I'd like to create the folder before opening it if it doesn't exist yet), but javascript or html on the client side is acceptable. For Internet Explorer, I can create that javascript in the C# code by wrapping it in the JavaScript( ... ) function built into MVC C# Controllers. When testing IE Tabs in Firefox and Chrome, I had to define it as an href link, not a function that opens a window, or IE Tabs wouldn't recognize it as a link. But neither of these were acceptable workarounds for our business needs.

推荐答案

在我提出一个可行的解决方案之前,请求已被删除,但是如果其他任何人仍在为这个问题而苦苦挣扎,我将介绍不需要任何工作站自定义的解决方法。

The request was dropped before I could come up with a feasible solution, but in case anyone else is still struggling with this problem I will describe workaround that would not require any workstation customization.

从技术上讲,他们不需要使用内置的在文件资源管理器中打开一个文件夹。相反,一种在不破坏任何浏览器安全性规则的情况下显示企业所需信息的创新方法是在不打开文件浏览器的情况下循环访问文件,然后在浏览器窗口中显示文件夹/文件列表。

They don't technically need to use the built-in file explorer to open a folder. Instead, a creative way to display the information the business wanted without breaking any browser security rules would be to iterate though the files without opening the file explorer and then display a list of folders/files in a browser window.

使用 Directory.EnumerateDirectories(filepath) Directory.EnumerateFiles(filepath)可以获得要显示的文件夹和文件的列表。当用户单击其中一个文件夹时,再次调用这些方法以获取下一级别的文件夹和文件名。当用户单击文件时,请下载/打开它。这些方法将文件夹和文件名作为字符串列表返回,因此您只需要在浏览器中使用自定义图标来呈现这些列表。 (方法来自C#的System.IO库。)

Using Directory.EnumerateDirectories(filepath) and Directory.EnumerateFiles(filepath) you can get a list of folders and files to display. When the user clicks one of the folders, call these methods again to get the next level of folders and filenames. When the user clicks a file, download/open it. These methods return the folder and file names as lists of strings, so you would just need to render the lists with custom icons in the browser. (The methods are from C#'s System.IO library.)

这篇关于如何通过Firefox和Chrome中网站上的链接打开文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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