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
2 Answers
Reset to default 3You 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.
- Add a file input field to the page
- Add
onchange
event listener to the input - Get the file
- 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
版权声明:本文标题:javascript - error: Not allowed to load local resource - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745532701a2662132.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论