Change button behavior according to URL

Asked

Viewed 167 times

0

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

site.com/search/hill climbing machine

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

Example with decreasing "DESC" (highest price)

URL:

site.com/search/hill climbing machine ?filter=desc

The button being the bet of 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/hill climbing machine ?filter=asc

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

standard behavior (no filter ? filter in URL) "filter for lower price"

  • What you want to do is use AJAX, right? And then modify some page content?

1 answer

0

I guess that’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
    }
});
  • However, considering that you are passing the sorting control variable via GET you should consider the possibility of processing the code via your page’s programming language instead of JS.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.