Why window.location is undefined for all properties in Safari 6 and Mobile Safari (iOS 6)

When i type

window.location 

I get undefined for all properties.

Here is my console:

enter image description here

+8
safari mobile-safari
source share
2 answers

This code works in Safari (6.0.1) and earlier

  // Get location for REST TARGETS lcnURI = window.location.protocol + "//" + window.location.hostname + ":" + window.location.port + "/rest/"; 

It looks like window.location is "out of context" when you look in the log. But on the spot it's good.

+5
source share

I can confirm this (Version 6.0 (8536.25)). As far as I can tell, Safari seems to be a bug.

Tested on jsbin (http://jsbin.com/enugoj/1/):

 console.log(window.location); console.log(window.location.pathname);​ 

Results in the Safari console:

 Location ancestorOrigins: undefined hash: undefined host: undefined hostname: undefined href: undefined origin: undefined pathname: undefined port: undefined protocol: undefined search: undefined __proto__: LocationPrototype /enugoj/1 

Results in Chrome (version 21.0.1180.89):

 Location ancestorOrigins: DOMStringList assign: function () { [native code] } hash: "" host: "jsbin.com" hostname: "jsbin.com" href: "http://jsbin.com/enugoj/1" origin: "http://jsbin.com" pathname: "/enugoj/1" port: "" protocol: "http:" reload: function () { [native code] } replace: function () { [native code] } search: "" toString: function toString() { [native code] } valueOf: function valueOf() { [native code] } __proto__: Location 1:14 /enugoj/1 
+4
source share

All Articles