Open local files(file://) using Chrome

前端 未结 3 2065
耶瑟儿~
耶瑟儿~ 2020-12-06 18:39

I have an page with some forms. All the links work fine in IE. They open in a new tab nicely when the hyperlink is click by the user; however, I realized that when Chrome is

相关标签:
3条回答
  • 2020-12-06 19:04

    You can't access to files outside your server or "SandBox", sandbox include the files that user push to the browser or to your server.

    If the access from browser to a pc files from web pages was possible, it would be a security problem.

    0 讨论(0)
  • 2020-12-06 19:08

    The answer is that you can't with your approach and more importantly you shouldn't. Chrome behavior is in fact the right behavior and it protects you from having malicious users and/or scripts accessing your local resources.

    The FILE protocol will access local or defined network named resources which will not be available to a remote user that visits the same page. In other words, you may have outsideserver mapped as a network resource/drive but someone else will not (This does not apply to IPs)

    Here's what you can do:

    • Move the code to a server side script(php, asp, etc) and stream the file back out. Found a quick example here on SO. I did not verify it though. Streaming a large file using PHP
    • Install a webserver on outsideserver and map a new site to the shared folder. You can then reference it via http (http://outsideserver.com/form1.pdf)
    0 讨论(0)
  • 2020-12-06 19:10

    Use the below extension for chrome. It will work.

    Enable local file links

    Below both options are working and tested.

    <a href="\\server\folder\">Link 2</a>
    
    <a href="file:///C:/folder/test.txt">Link 3</a>
       
    
    0 讨论(0)
提交回复
热议问题