Cannot open local file - Chrome: Not allowed to load local resource

后端 未结 14 1466
不知归路
不知归路 2020-11-22 12:01

Test browser: Version of Chrome: 52.0.2743.116

It is a simple javascript that is to open an image file from local like \'C:\\002.jpg\'

function run(         


        
14条回答
  •  清酒与你
    2020-11-22 12:47

    I've encounterd this problem, and here is my solution for Angular, I wrapped my Angular's asset folder in encodeURIComponent() function. It worked. But still, I'd like to know more about the risk of this solution if there's any:

    ```const URL = ${encodeURIComponent(/assets/office/file_2.pdf)} window.open(URL)

    I used Angular 9, so this is my url when I clicked open local file:
    ```http://localhost:4200/%2Fassets%2Foffice%2Ffile_2.pdf```
    

提交回复
热议问题