Ie 8.0 Access Denied When Trying To Open Local Files

浪子不回头ぞ 提交于 2019-12-31 06:54:25

问题


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?

<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

回答1:


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.

Your options are limited, but can include:

  1. developing a flash component to access the user's local drive.

  2. Implement the site as an HTA (html application) which gives promoted access to the user's file system.

  3. 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.)

  4. Develop a pluggin or bho object (similar to flash component, but written in C++ or C#)

  5. Create an IE Context Menu - http://msdn.microsoft.com/en-us/library/bb735853(v=vs.85).aspx which will also have elevated privileges.

As a side note proper file schemes for c:\ paths should look like this:

file:///c:/documents%20and%20settings/file.jpg

Notice the three / after file:, uri-escaped spaces, and all \ are switched to /



来源:https://stackoverflow.com/questions/4339734/ie-8-0-access-denied-when-trying-to-open-local-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!