Window.location.search

Can window.location.search be null or undefined in any browser? Most of them I tried IE8 / 9, FF, Chrome, Safari - all empty lines.

I just want to know if I need to check for zero before doing an operation on it.

+5
source share
2 answers

There should be blank lines. But using type conversion:

if(window.location.search)

will work anyway. If a search is given, it will definitely be an empty string and then true will be evaluated.

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 at the end.

+3
source

IE location.search , URL = .

0

All Articles