为什么window.location.search为空?

时间:2014-05-21 17:01:36

标签: javascript

如果我console.log(window.location)我明白了:

Location {replace: function, assign: function, ancestorOrigins: DOMStringList, origin: "https://localhost:3000", hash: "#/account/content?hello=world"…}
ancestorOrigins: DOMStringList
assign: function () { [native code] }
hash: "#/account/content?hello=world"
host: "localhost:3000"
hostname: "localhost"
href: "https://localhost:3000/#/account/content?hello=world'"
origin: "https://localhost:3000"
pathname: "/"
port: "3000"
protocol: "https:"
reload: function reload() { [native code] }
replace: function () { [native code] }
search: ""
toString: function toString() { [native code] }
valueOf: function valueOf() { [native code] }
__proto__: Location

我希望search?hello=world,但事实并非如此。

为什么?

我正在使用Chrome 35

1 个答案:

答案 0 :(得分:19)

因为?hello=world在您的情况下不被视为查询字符串 它是anchor#)的一部分,可以使用

获得
window.location.hash