How can I check if the query string contains a q= in it using JavaScript or jQuery?
q=
Try this
//field "search"; var pattern = /[?&]search=/; var URL = location.search; if(pattern.test(URL)) { alert("Found :)"); }else{ alert("Not found!"); }
JSFiddle: https://jsfiddle.net/codemirror/zj4qyao2/