I have a views page in which I can search by narrowing down to a category. It also has a pager. So you could get something like Category: X page: 2.

When I found the result I'm looking for I navigate to that result. But when I want to go back my category and page I was on are lost.

I've worked around this by using a history.pushState in which my URL changes to something like ?f[0]=field_category:3&page=2.

This works perfectly fine, and I can navigate back and forth without too much hassle.


The previous button and the first button in my pager don't work properly anymore! The previous button goes to the previous page until it reaches page 2, if I'd like to go back to page 1 it navigates back to page 3, and when pressing previous on page 3 it goes back to 2 etc. etc.

The first button just navigates between the current and the previous page. 5 to 4 => 4 to 5 => 5 to 4 etc. etc.

What I'm doing in my javascript on an ajaxComplete is add all the variables I want in my url to an array. When I've collected them all I join them to a single string which I put into the pushState:

query_vars[query_vars.length] = 'page=' + (current_page); //for every variable
query_string = '?' + query_vars.join('&');
var stateObj = {};
window.history.pushState(stateObj, "New", href + query_string);

In short:

Why does my previous button won't go back to page 1(but instead goes to page 3) And why does my first button jumps between the current and the previous page and vice versa?


Opening the "previous" button's link in a new tab works fine!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.