How to make a window.location.href judge?
if window.location.href not match ?search=, make the current url jump to http://localhost/search?search=car
my code not work, or I should use indexOf to make a judge? Thanks.
if(!window.location.href.match('?search='){
window.location.href = 'http://localhost/search?search=car';
}
A couple of things: you’re missing a closing paren, and you need to escape the ? because it’s significant to regular expressions. Use either
/\?search=/or'\\?search='.or