0

hi all i am trying to hide content for a ppc campaign, so if they come from the link they will have something like "/?utm_source=google" on the url

Ive got the following but it only works for that exact url

 var url = "http://mysite.com/?utm_source=google";
  if (location.href==url){
    $('div').hide();
  }

Ideally it needs to work for multiple pages i.e. http://mysite.com/page-one/?utm_source=google

Just wondering if anyone knows a way around this?

Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
Adam
  • 812
  • 3
  • 13
  • 22
  • possible duplicate of [Method like String.contains() in JavaScript](http://stackoverflow.com/questions/1789945/method-like-string-contains-in-javascript) - this is essentially what OP is asking. – Benjamin Gruenbaum Aug 19 '13 at 11:40
  • Why don't you use getting the Query String? That will always provide you the query string name and its value too. – Afzaal Ahmad Zeeshan Aug 19 '13 at 11:47

2 Answers2

0

use a regexp match:

  if (location.href.match(/utm\_source\=google/ig)){
    $('div').hide();
  }
kayen
  • 4,838
  • 3
  • 19
  • 20
0
var option = 'coke';
    var url = window.location.href;
    option = url.match(/option=(.*)/)[1];
    showDiv(option);
});
function showDiv(option) {
    $('.boxes').hide();
    $('#' + option).show();
}

Read the Contents

Vaibs_Cool
  • 6,126
  • 5
  • 28
  • 61