2

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.

5
  • If it's local, why are you typing the IP? Commented Jul 16, 2014 at 17:17
  • sorry, i mean within the network, i have to point to different IP address.@DaniloValente 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 computer? 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. Commented Jul 16, 2014 at 17:38
  • 1
    But... you can't read arbitrary files in arbitrary computers just by composing a path. You need a network protocol that actually implements the transfer :-? Commented Jul 16, 2014 at 17:44

2 Answers 2

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

      })
-1

file:// work only on your computer.

It's a security.

4
  • their should be a way to make chrome work with it as IE supports this. @Hors Sujet Commented Jul 16, 2014 at 17:25
  • Try : file://///154.66.111.123/ but browsers have different level of security (Try to drag'n'drop file on your browser). Commented Jul 16, 2014 at 17:28
  • I tried ,it is not working, same error its displaying on browser console : "Not allowed to load local resource: file://154.66.111.123/SD/SPRD/index.htm " . @Hors Sujet Commented Jul 16, 2014 at 17:36
  • "Not allowed to load local resource" is security warning. Commented Jul 16, 2014 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.