Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
34
rated 0 times [  39] [ 5]  / answers: 1 / hits: 84849  / 12 Years ago, thu, december 27, 2012, 12:00:00

Same question as here but I need to go to local URL's in Firefox



I tried with code like



var url = file:///E:/Test/Test.htm;
window.location.href = url;


but id didn't work. Tried to go with window.location = url; and also tried with url = file://E:/Test/Test.htm; (double / instead of triple /) and still doesn't work.



Thanks


More From » url

 Answers
1

When I try this:



window.location.href = file:///C:/Users/Cerbrus/Documents/SomeFile.js


(Yes, it is a valid path.)



Chrome throws me this error:




Not allowed to load local resource: file:///C:/Users//Documents/File.js




This is because JavaScript does not have access to local files (due to it being sandboxed), and you're setting the new url with JavaScript.

SandBoxed means a technology has restricted (or no) access outside a certain set of bounds. In the case of browsers, this means that the code that runs on the page can not access files on your system (Otherwise, it would be easy to steal data, by just having a look at the user's file system).



However,



Say, I have 2 files:




C:/Test/Test.htm

C:/Test/Test1.htm




Test.htm contains only this:



<script>
window.location = file:///C:/Test/Test1.htm;
</script>


This will actually redirect to Test1.htm, since the target file is on the same domain as where the source file's from.


[#81206] Tuesday, December 25, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tayla

Total Points: 681
Total Questions: 102
Total Answers: 108

Location: Marshall Islands
Member since Tue, Sep 21, 2021
3 Years ago
tayla questions
Fri, Mar 5, 21, 00:00, 3 Years ago
Wed, Oct 28, 20, 00:00, 4 Years ago
Thu, Apr 9, 20, 00:00, 4 Years ago
;