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 02 Answers
Reset to default 3Should 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
评论列表(0条)