Use document.baseURI instead of location.href
stbuehler opened this issue · 1 comments
In https://github.com/getify/LABjs/blob/master/LAB.src.js#L18 root_page
is calculated from location.href
; it should use document.baseURI
instead (or document.baseURI || location.href
?) as relative urls should be relative to the base uri, which can be changed with <base href=...>
.
I have been asked to do this before, but it was an intentional design choice way back at the beginning, not a mistake, not to support LABjs being relative to the <base>
tag of a page. Back then, <base>
tags were a big problem for IE6, and moreover, back then (at least), IE didn't support document.baseURI
.
So I elected to instead add the BasePath
configuration to allow relative URLs. Note: the BasePath
should be absolute, and not relative (as it itself would be considered relative to the page, which will likely produce strange results).
LAB.setGlobalDefaults({ BasePath: "http://some.tld/other/path" });
// or
LAB.setOptions({ BasePath: "http://some.tld/other/path" })
.script(...)
...
So, if you set the LAB configuration BasePath
to the same as the absolute value in your <base>
tag, you should get your desired behavior, and that should be reliable across all browsers. Moreover, if you're using <base>
for only your script tags, LABjs' configuration makes <base>
unnecessary. :)