elin-r
10/4/2016 - 10:30 AM

Display block based on URL query

Display block based on URL query

<script type="text/javascript">

  // Get URL
  var url = window.location.href;

  // Get DIV
  var bluediv = document.getElementById('blue');
  var reddiv = document.getElementById('red');
  var greendiv = document.getElementById('green');

  // Check if URL contains the keyword
  if( url.search( 'blue' ) > 0 ) {
      // Display the message
      bluediv.style.display = "block";
  }

  else if( url.search( 'red' ) > 0 ) {
      // Display the message
      reddiv.style.display = "block";
  }

  else if( url.search( 'green' ) > 0 ) {
      // Display the message
      greendiv.style.display = "block";
  }
</script>