admin管理员组

文章数量:1429064

I'm constructing the URL dynamically pointing to local IP address in my action class,
Below is the URL constructed:

<a file='#' onClick=window.open('file://154.66.111.123/SD/SPRD/index.htm','_self') >Click Here </a>

The above URL works fine in IE, but in chrome i could not able to access that URL, below is the exception noticed on browser console:

Not allowed to load local resource:file://154.66.111.123/SD/SPRD/index.htm

How can i access local file system from chrome?Please suggest. Thanks.

I'm constructing the URL dynamically pointing to local IP address in my action class,
Below is the URL constructed:

<a file='#' onClick=window.open('file://154.66.111.123/SD/SPRD/index.htm','_self') >Click Here </a>

The above URL works fine in IE, but in chrome i could not able to access that URL, below is the exception noticed on browser console:

Not allowed to load local resource:file://154.66.111.123/SD/SPRD/index.htm

How can i access local file system from chrome?Please suggest. Thanks.

Share Improve this question asked Jul 16, 2014 at 17:16 user3711336user3711336 231 gold badge1 silver badge7 bronze badges 5
  • If it's local, why are you typing the IP? – Danilo Valente Commented Jul 16, 2014 at 17:17
  • sorry, i mean within the network, i have to point to different IP address.@DaniloValente – user3711336 Commented Jul 16, 2014 at 17:19
  • Please clarify... Are you trying to load a network share through a UNC path? As if typing \\154.66.111.123\SD\SPRD\index.htm on a Windows puter? – Álvaro González Commented Jul 16, 2014 at 17:35
  • No , iam getting that URL from dataBase and if users want to go to that path, they need to click on the link so that users are directed to that path. Got the URL from database and constructed <a file='#' onClick=window.open in my action class along with the URL. @ Álvaro G. Vicario. – user3711336 Commented Jul 16, 2014 at 17:38
  • 1 But... you can't read arbitrary files in arbitrary puters just by posing a path. You need a network protocol that actually implements the transfer :-? – Álvaro González Commented Jul 16, 2014 at 17:44
Add a ment  | 

2 Answers 2

Reset to default 3

You can't access a file like that for security reasons. But you can access a file without uploading it using javascript. one way to do that is using file input field.

  1. Add a file input field to the page
  2. Add onchange event listener to the input
  3. Get the file
  4. Create the url using URL.createObjectURL function

sample code

let input = document.querySelector("#input");

input.addEventListener("change", (e)=>{
        let file = input.files[0];
        let url = URL.createObjectURL(file); // A valid URL that you can use on the page

      })

file:// work only on your puter.

It's a security.

本文标签: javascripterror Not allowed to load local resourceStack Overflow