当我输入
window.location
我在所有属性上都不确定。
这是我的控制台:
此代码适用于 Safari (6.0.1) 及更早版本
// Get location for REST TARGETS
lcnURI = window.location.protocol + "//" + window.location.hostname + ":"
+ window.location.port + "/rest/";
当您查看日志时,window.location 似乎“脱离了上下文”。但是在使用的地方还好。
I can confirm this (Version 6.0 (8536.25)). Seems to be a Safari bug, as far as I can tell.
Tested on jsbin (http://jsbin.com/enugoj/1/):
console.log(window.location);
console.log(window.location.pathname);
Results in Safari's 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