dcsimg
Results 1 to 4 of 4

Thread: Chrome blocking reading a file whilst firefox works

  1. #1

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Java (JSP) Hell!
    Posts
    5,294

    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?

    BOFH Now, BOFH Past, Information on duplicates

    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...

  2. #2
    March 2015 Winner kfcSmitty's Avatar
    Join Date
    May 2005
    Location
    Kingston, Ontario
    Posts
    2,129

    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>

  3. #3
    Fanatic Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    880

    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

  4. #4

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Java (JSP) Hell!
    Posts
    5,294

    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.

    BOFH Now, BOFH Past, Information on duplicates

    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
  •  



Featured


Click Here to Expand Forum to Full Width