Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use javascript to find parameter in url and then apply if then logic

Tags:

I am trying to make my page perform an action only if it sees that a particular parameter is present in the url.

I essentially want the javascript code to do this:

consider an example page such as: http://www.example.com?track=yes

If a page loads that contains the parameter 'track' within the url, print 'track exists', else if the 'track' parameter doesn't exist print 'track does not exist'

like image 425
rob melino Avatar asked Nov 18 '11 23:11

rob melino


1 Answers

This should work:

if (window.location.search.indexOf('track=yes') > -1) {     alert('track present'); } else {     alert('track not here'); } 
like image 84
deviousdodo Avatar answered Oct 13 '22 11:10

deviousdodo