Fix URL resolution for file:// URLs (closes #1)

Although this should fix the "null" appearing in the generated
"baseurl", opening the pages via file:// will most likely still not work
due to the Same-Origin Policy.
master
Hauke D 7 years ago
parent 58c06898b6
commit fdfcf63f91

@ -171,6 +171,12 @@ Perl.init = function (readyCallback) {
throw "Perl: can't call init in state "+Perl.state; throw "Perl: can't call init in state "+Perl.state;
Perl.changeState("Initializing"); Perl.changeState("Initializing");
var baseurl = new URL(getScriptURL()); var baseurl = new URL(getScriptURL());
if (baseurl.protocol=='file:')
// Note that a lot of things still won't work for file:// URLs
// because of the Same-Origin Policy.
// see e.g. https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSRequestNotHttp
baseurl = baseurl.href.substring(0,baseurl.href.lastIndexOf('/'));
else
baseurl = baseurl.origin + baseurl.pathname.substring(0,baseurl.pathname.lastIndexOf('/')); baseurl = baseurl.origin + baseurl.pathname.substring(0,baseurl.pathname.lastIndexOf('/'));
Perl.readyCallback = readyCallback; Perl.readyCallback = readyCallback;
Module = { Module = {

Loading…
Cancel
Save