Why different EOL in html causes javascript in Safari to behave differently? [closed]
Asked Answered
K

0

11

I have two identical html files (except for EOL character - one is LF and the other is CRLF), which I use to load 2 audio files using XMLHttpRequest. I don't use any web server (because the purpose is to load it in ipad and run it without any web server) - I just use open those with Safari (for Mac).

The mind-boggling thing is, the file with LF endlines is able to load the audio files just fine, but the one with CRLF got:

Cross origin requests error (XMLHttpRequest cannot load file:///directories_to_files/cheer_and_clap.mp3. Cross origin requests are only supported for HTTP.)

You can have a look at the files. I haven't tested on Safari for Windows version yet.

p.loadBuffer = function(url, index) {
    var request = new XMLHttpRequest();
    console.log(url);
    request.open("GET", url, true);
    request.responseType = "arraybuffer";
        console.log(request);
    }
    request.onerror = function() {
        alert('BufferLoader: XHR error');
    }
    request.send();
}

Any explanation for why this is happening?

Kermis answered 25/10, 2012 at 15:34 Comment(6)
I don't get the same error as you I'm afraid - for both files I get INVALID_STATE_ERR: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable. console.log(request); does get echoed to the console log tho.Ouabain
both won't work, as local files are indeed, not allowed for XHR. there must be something else.Cosetta
Thanks guys. That's really strange.. I tried everything (including clearing the cache, restart the comp, etc.), it still happen on my computer, but testing on another computer both of them don't work as it supposed to be so.Kermis
I think it's the byte order mark, the CRLF file has it at the beginning while the LF file doesn't have it. Try to remove it, for instance use the command dd if=CRLFEOL.html of=CRLFEOL2.html bs=1 skip=3Alcina
they both should have been denied because usually xmlHttp requests are not allowed cross domains. this is for security reasons.Barogram
What version of safari are you using? I tried both files in Safari Version 6.0 (8536.25). Both work for me. However, when I loaded the same files in Google Chrome, they give the XHR error.Observant

© 2022 - 2024 — McMap. All rights reserved.