I just want to test the URL for a question mark ? however I keep getting an invalid quantifier error message…
alert(window.location.href.search('?'));
I then tried things like…
alert(window.location.href.search('\?'));
/
alert(window.location.href.search(\?));
…without any luck.
.searchconverts the argument to a RegExp./?/is an invalid RegExp. The escape does not work either, because a single backslash in the string is not converted to a RegExp-escaping backslash.Use
indexOfinstead: