|
-
Sep 12th, 2018, 08:26 PM
#1
Thread Starter
Don't Panic!
Chrome blocking reading a file whilst firefox works
Hi
Bit stuck as I dont like the ide on firefox but have to use it because chrome is blocking a file.
I have a html and several js files. I also have a json formatted txt config file I am trying to get to be read into the js.
IIS server set up but I`m not sure it is using that atm.
Code:
loadConfig(){
//ajax
console.log("loadConfig");
var reader = new XMLHttpRequest() || new ActiveXObject('MSXML2.XMLHTTP');
reader.open('GET', './js/config.txt', true);
reader.setRequestHeader("Content-type","text");
reader.onreadystatechange = function(){
if( reader.readyState == 4 ){
//loop reader.responseText and import into the array
//or parse as JSON and then loop
console.log(reader);
jObj = JSON.parse(reader.responseText);
Firefox gives a warning about the file incorrectly formatted but still parses it ok.
Chrome refuses to try stating
Failed to load file:///C:/Dev/html/js/config.txt: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
I ran the html file directly in chrome. rather than through a web page address (I can try to set it up on the local host I guess).
because chrome blocks it the readder is an empty string to json parse errors.
I assume this is a security thing from chrome, is there a way around it or can I only test using local host? Or just use firefox?
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Sep 13th, 2018, 07:10 AM
#2
Re: Chrome blocking reading a file whilst firefox works
Looks like you can launch chrome with a specific flag to tell it to allow it:
<path to chrome>\chrome.exe --allow-file-access-from-files <file you want to run>
-
Sep 13th, 2018, 08:28 AM
#3
Re: Chrome blocking reading a file whilst firefox works
Put the file where the webserver can access it (i.e., C:\inetpub\wwwroot\Dev\html\js) so you could then use http://localhost/Dev/html/js/config.txt
-
Sep 13th, 2018, 12:30 PM
#4
Thread Starter
Don't Panic!
Re: Chrome blocking reading a file whilst firefox works
@kfcSmitty : Thanks. Good to know. This will work for straight html double click without needing the server? Needs an exact path too?
@topshot : easiest way ... right? I'll try tonight.
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|