javascript - window.location.search - Stack Overflow

Can window.location.search be null or undefined in any browser? Most of them i tried IE89, FF, Chrome,

Can window.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.

Can window.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.

Share Improve this question asked Apr 28, 2011 at 8:53 user460025user460025 6291 gold badge11 silver badges20 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 3

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744394777a4572085.html

相关推荐

  • javascript - window.location.search - Stack Overflow

    Can window.location.search be null or undefined in any browser? Most of them i tried IE89, FF, Chrome,

    7天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信