Clear subfilter selection

1

I have an option on my site that is easy to search for products by subfilters, but now I have a problem, I need to "clean" this navigation, going back to the before search, I used an uninteresting technique 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 client navigates through more than one filter it will return exactly where it went. I could not find a solution for this, if you prefer to see the example, go here and navigate through the subfilters and click the "clean filters" button:

Developing site

    
asked by anonymous 13.02.2015 / 01:01

1 answer

1

I believe you do not have access to PHP code. If you have, ideally you link the clean filters button to: link

If you can only change the Javascript code, there is 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>
    
13.02.2015 / 02:48