windows 即尝试打开本地文件时 8.0 访问被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4339734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ie 8.0 Access Denied When Trying To Open Local Files
提问by Hemanth
This script works in IE 6 but not in IE 8.0 My users now get an "Access Denied error". What settings do I refer my users to do enable local file access so that this script will work?
此脚本适用于 IE 6 但不适用于 IE 8.0 我的用户现在收到“拒绝访问错误”。我应该推荐我的用户进行哪些设置来启用本地文件访问,以便此脚本可以工作?
<script language="JavaScript">
function viewFile(selectedItem) {
for (i=0; i<selectedItem.options.length; i++) {
if ((selectedItem.options[i] != null) && (selectedItem.options[i].selected == true)) {
window.open("file://"+selectedItem.options[i].text);
}
}
}
</script>
Users can select multiple files from local drive. The list is stored in a text box and then clicks on one selected file from the list.
用户可以从本地驱动器中选择多个文件。该列表存储在一个文本框中,然后单击列表中的一个选定文件。
Example:
例子:
selectedItem.options[i].text = C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Sunset.jpg
回答by Marcus Pope
You're not going to be able to do that "out of the box" anymore as IE8's security model is much stricter than IE6.
由于 IE8 的安全模型比 IE6 严格得多,您将无法再“开箱即用”地做到这一点。
Your options are limited, but can include:
您的选择有限,但可以包括:
developing a flash component to access the user's local drive.
Implement the site as an HTA (html application) which gives promoted access to the user's file system.
Have the visitors customize their IE security settings by adding your site to the list of trusted domains and then give trusted domains access to the file:/// protocol (I'm not sure which security setting applies to this particular feature, or if one is even available.)
Develop a pluggin or bho object (similar to flash component, but written in C++ or C#)
Create an IE Context Menu - http://msdn.microsoft.com/en-us/library/bb735853(v=vs.85).aspxwhich will also have elevated privileges.
开发闪存组件来访问用户的本地驱动器。
将站点实现为 HTA(html 应用程序),从而提供对用户文件系统的提升访问权限。
让访问者通过将您的站点添加到受信任域列表中来自定义他们的 IE 安全设置,然后授予受信任域访问 file:/// 协议的权限(我不确定哪个安全设置适用于此特定功能,或者甚至可用。)
开发插件或 bho 对象(类似于 flash 组件,但用 C++ 或 C# 编写)
创建一个 IE 上下文菜单 - http://msdn.microsoft.com/en-us/library/bb735853(v=vs.85).aspx,它也将具有提升的权限。
As a side note proper file schemes for c:\ paths should look like this:
作为旁注, c:\ 路径的正确文件方案应如下所示:
file:///c:/documents%20and%20settings/file.jpg
file:///c:/documents%20and%20settings/file.jpg
Notice the three /
after file:
, uri-escaped spaces, and all \
are switched to /
注意uri 转义/
后的三个file:
空格,并且\
都切换到/