开发者

window.location.search

Can w开发者_JS百科indow.location.search be null or undefined in any browser? Most of them i tried IE8/9, FF, Chrome, Safari is all empty strings.

Just want to know if i have to null check before doing string operation on it.


Should be empty strings. But using type conversion:

if(window.location.search)

will work in any case. If the search is set, it will definitely be a non empty string and evaluate to true then.

Or use typeof:

if(typeof window.location.search === "string")

but this is also true for an empty string. It depends on what you want to do in the end.


In IE, location.search can be an empty string even though a ?key=value part is present in the URL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜