当我输入的时候
window.location我在所有属性上都是未定义的。
这是我的控制台:

发布于 2012-10-17 03:44:02
此代码可在Safari (6.0.1)及更早版本中运行
// Get location for REST TARGETS
lcnURI = window.location.protocol + "//" + window.location.hostname + ":"
+ window.location.port + "/rest/";当您在日志中查看时,似乎window.location“脱离了上下文”。但是在原地使用它是很好的。
发布于 2012-09-17 19:23:58
我可以确认这一点(版本6.0 (8536.25))。据我所知,这似乎是Safari的bug。
在jsbin (http://jsbin.com/enugoj/1/)上测试:
console.log(window.location);
console.log(window.location.pathname);Safari控制台中的结果:
Location
ancestorOrigins: undefined
hash: undefined
host: undefined
hostname: undefined
href: undefined
origin: undefined
pathname: undefined
port: undefined
protocol: undefined
search: undefined
__proto__: LocationPrototype
/enugoj/1Chrome (版本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 https://stackoverflow.com/questions/11198349
复制相似问题