How to check if a query string value is present via JavaScript?
You could also use a regular expression:
/[?&]q=/.test(location.search)
var field = 'q';
var url = window.location.href;
if(url.indexOf('?' + field + '=') != -1)
return true;
else if(url.indexOf('&' + field + '=') != -1)
return true;
return false