Clear selection of subfilter

Asked

Viewed 404 times

1

I have an option on my site that is the facility to search the products by subfilters, but now I have a problem, I need to "clean" this navigation, going back to before research, I used a technique not interesting in trying to solve the problem, create a button and put in it the following code:

<a class="button orange"href="javascript:window.history.go(-1)">Limpar Filtros</a>

But of course, I have some problems with that, if the customer navigates through more than one filter he will return exactly where he passed. I could not have a solution for this, if you prefer to see the example, go here and browse the subfilters and click on the "clean filters":

Website under development

  • The javascript:window.history.go(-1) command does the same as a click on the "Back Page" in the browser. With its current structure, the fastest way to clean the filters is to redirect to the initial category. But the ideal solution would be your products loaded through AJAX keeping your filters untouched.

1 answer

1


I believe you don’t have access to PHP code. If you do, ideally link the clear filters button to: http://moveissaobento.com.br/msb/produtos.php?dep=2&sub=14

If it is only possible to change the Javascript code, it will a solution:

window.goBackToOriginalQuery = function () {
  var query = window.location.search.replace('?','').split('&');
  var depParam = '', subParam = '';
  for (var i = 0, j = query.length-1; i<j; i++) {
     var currentParam = query[i];
     if (currentParam.indexOf('dep') !== -1){
       depParam = currentParam;
     } else if (currentParam.indexOf('sub') !== -1) {
       subParam = currentParam;
     }
  }

  var originalURL = window.location.protocol + '//' + window.location.host + '/msb/produtos.php?' + depParam + '&' + subParam;

  window.location.replace(originalURL);  
}

And in HTML:

<a class="button orange"href="javascript:window.goBackToOriginalQuery()">Limpar Filtros</a>
  • Hello @Breno Calazans, your tips were really cool, but the first is that it fit better, thank you.

Browser other questions tagged

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