8

I have an issue in a non production environment in Internet Explorer 11 where

window.location.origin is undefined.

However, in the production environment this value actually returns

window.location.origin = http://www.myproductionwebsite.com

This issue only exists in Internet Explorer and works fine in Chrome and Firefox across production and non production environments, which has lead me to believe its the way that the Chakra JavaScript Engine in IE11 populates origin.

I have also looked at the request and response headers across production and non production environment and all the parameters are identical.

How does Internet Explorer 11 calculate window.location.origin differently to Chrome or Firefox?

lissettdm
  • 12,267
  • 1
  • 18
  • 39
UsainBloot
  • 816
  • 6
  • 20
  • What is the value of `window.location.href` in the test environment? – Barmar Sep 22 '15 at 16:39
  • `window.location.href` in the test environment is the same as the URL at the top. I'm just wondering how IE11 obtains the `origin` as its `undefined` in the test env and `http://www.myproductionwebsite.com` in production. Maybe it uses DNS? – UsainBloot Sep 22 '15 at 16:45
  • I don't see why it would use anything other than just copying the beginning of the URL in `.href`. DNS doesn't have information about URLs. – Barmar Sep 22 '15 at 16:47
  • Hmmm its really strange, its not causing me an issue as I can work around it, just curious. – UsainBloot Sep 22 '15 at 16:49
  • Could you be running in compatibility mode in the test environment? Older versions of IE don't have `origin`. – Barmar Sep 22 '15 at 16:49
  • `window.location.origin` was first added in IE11. – Barmar Sep 22 '15 at 16:51
  • Is this on Windows 10, as I have an issue with window.location.origin not working correctly on a site in IE 11 on Windows 10 (which is a different version to IE 11 on Win 7/8: 11.0.10240.16384 vs 11.0.9600.17842) – Paul Manzotti Sep 23 '15 at 14:37
  • This is on Windows 7. Something else that may contribute to it is that I'm using a network where only port 80 and 443 are open to the internal environment where the test site is hosted. Could this contribute to it? I would have just thought that ie would obtain the value using substrings of the url. – UsainBloot Sep 23 '15 at 14:46
  • 2
    Are you still facing this issue? Could this bug be related to it? https://connect.microsoft.com/IE/feedback/details/1763802/location-origin-is-undefined-in-ie-11-on-windows-10-but-works-on-windows-7 – William Feb 14 '16 at 17:18

1 Answers1

7

Intranet sites are set to Compatibility View, which disables window.location.origin:

Pages will run in Compatibility View unless they explicitly specify another document mode. This option can be disabled using the Tools > Compatibility View Settings menu.

Sites are placed in the Intranet Zone based on the following criteria:

Direct Mapping. As with other Zones, users or network admins may map a list of URL patterns into the Local Intranet Zone. This list is viewable by clicking Tools > Internet Options > Security > Local Intranet > Sites > Advanced.

The PlainHostName rule (aka “The Dot rule”). If the URI’s hostname doesn’t contain any periods (e.g. http://team/) then it is mapped to the Local Intranet Zone.

The fixed Proxy Bypass list. If the user has a fixed proxy specified inside Tools > Internet Options > Connections > LAN Settings, then sites listed to bypass that proxy will be mapped to the Local Intranet zone. The fixed proxy bypass list can be found by clicking the Advanced button; it’s at the bottom of the screen in the box labeled Exceptions.

(WPAD) Proxy Script. If the user’s proxy configuration is “Automatically detect settings” or “Use automatic configuration script” inside Tools > Internet Options > Connections > LAN Settings, the browser will run the FindProxyForUrl function in the specified WPAD proxy configuration script to determine which proxy should be used for each request. If the script returns “DIRECT”, the browser will bypass the proxy and the site will be mapped into the Local Intranet Zone. When mapping a URL to a Zone, URLMon will call the FindProxyForUrl function to determine if the bypass rule applies. One interesting twist is that the proxy script may itself call dnsResolve to get a site’s IP address and use that information as a part of its determination.

Full-sized flowchart detailing how document modes are chosen in IE11

References

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265