0

I want to set a few options in a URL and if the URL is set to make something happen, i know how to do this in PHP etc... but never before in jQuery and wondering if it is possible (im sure it is) i want to have a set of links like.....

/?banner=banner1
/?banner=banner2
/?banner=banner3

Any ideas on how i can say something like if banner = banner1 do this etc...

im assuming might be using thing like $.get() maybe?

Thanks in advance

James Brandon
  • 1,350
  • 3
  • 16
  • 43

4 Answers4

1

I use this native function to do that:

function pget( name ){
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp ( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

Name is the name of the parameter (in your case banner). If it not exists, the function returns empty string.

I hope it helps.

Regards

Mario Araque
  • 4,562
  • 3
  • 15
  • 25
1

You can also use as

 var url = "http://example.com/?banner=banner1";
 var pieces = url.split("/?");

 // pieces[0] == "banner=banner1"

use as you want then.

Amit
  • 15,217
  • 8
  • 46
  • 68
0

I think that has been covered a lot of times : https://stackoverflow.com/search?q=jquery+get+url+parameters

Community
  • 1
  • 1
Manuszep
  • 813
  • 11
  • 20
-1

You should use function .attr( 'href' )

For example:

if( $( 'a.first' ).attr( 'href' ) == $( 'a.second' ).attr( 'href' ) ){

};
danielg44k
  • 55
  • 4