scala-js/scala-js-dom

window.location.origin does not exist on IE

easel opened this issue · 3 comments

easel commented

Unfortunately, window.location.origin does not exist on "some" versions of IE. Apparently IE 11 on windows 7 and the latest windows 10 have it, but everything I've tried doesn't have it. See https://connect.microsoft.com/IE/feedback/details/1763802/location-origin-is-undefined-in-ie-11-on-windows-10-but-works-on-windows-7

Probably the solution is to include a polyfill. Modernizr has one, is it worth considering just including modernizr?

Otherwise, this is the polyfill needed.

if (!window.location.origin) {
  window.location.origin = window.location.protocol + "//" 
    + window.location.hostname 
    + (window.location.port ? ':' + window.location.port : '');
}
easel commented

I'm happy to provide a PR, but I'm not finding a spot for polyfills in scala-js-dom. Should it go in scala-js itself? Alternatively, we could change the signature on .origin, or just document the need for the polyfill.

sjrd commented

scala-js-dom doesn't provide poyfills, as such. That's not supposed to be its job.

If IE does not support origin, especially IE11, I think it would be fair to change the signature to a js.UndefOr.

easel commented

Ok, fair enough. PR coming shortly. Thanks