Change button behavior according to URL

0

How can I change the behavior of a button according to the URL? I have the following URL, eg:

  

site.com/search/ hill climbing machine

The button would be something to filter according to the price, being growing or decreasing .

Example with "DESC" decreasing (highest price)

URL:

  

site.com/search/ slope escalator ? filter = desc

The button being the one affixed to the URL:

<a href="site.com/search/maquina de subir ladeira?filter=asc">Filtrar por menor preço</a>

or, for increasing values:

Example with increasing ASC (lowest price)

  

site.com/search/ slope escalator ? filter = asc

<a href="site.com/search/maquina de subir ladeira?filter=desc">Filtrar por maior preço</a>

Being the default behavior (no filter? filter in the URL) "filter for less price"

    
asked by anonymous 16.08.2016 / 01:14

1 answer

0

I think it's what you're looking for:

$(document).ready(function(){
    var get = document.URL;
    if(get.match(/filter=asc/i)){
       //Faz isso
    }
    else if(get.match(/filter=desc/i)){
       //Faz aquilo
    }
    else{
       //Faz outra  coisa
    }
});
    
16.08.2016 / 15:15