regex - Why is this simple javascript not working? -
new js here. trying detect existence of string in present page's url this:
var url = window.location; var param = /\?provider=/i; if (url.search(param) != -1) { alert('it exist'); } else alert('it not exist'); it works when manually define url variable so
var url = 'http://google.com?provider=' but when try grab dynamically in above script doesn't work, there way make work?
you want href property on location object, this:
var url = window.location.href; var param = /\?provider=/i; if (url.search(param) != -1) { alert('it exist'); } else alert('it not exist'); location isn't string, it's object, , doesn't have .search() method, .href string does.
Comments
Post a Comment