Mou
Mou

Reputation: 16282

prevent browser url change when managing history

Normally when we move from one section to another using ajax then history is not saved and that is why we can not click on browser back button. i am showing data in tabular format and also showing pager link so user can go to see next sets of data but initially history was not managed. i go through a tutorial and implement to save history forcefully by js library called jquery.ba-bbq.min.js this way

$(window).trigger('hashchange');

when people click on back/forward button then haschange function is firing

$(window).bind('hashchange', function (e) {
    var searchTerm = '';
    var pageIndex = e.getState("pageIndex") || 0;
    pageIndex = parseInt(pageIndex);
    searchTerm = e.getState("keyword") || '';
    if (searchTerm != null && searchTerm != '') {
        $("input[id*='txtSearch']").val(searchTerm);
        block();
        Search(searchTerm, pageIndex);
    }
});

this way calling setHistory() forcefully insert data to history when user click on pager link

calling setHistory(1, SearchTerm);

    function setHistory(pageIndex, SearchTerm) {
        $.bbq.pushState({ pageIndex: pageIndex, keyword: SearchTerm });
    }

my code works fine the problem is url is getting changed in browser address bar. so i like to know is there any way to maintain history without changing url in address bar?

if possible guide me how to do that or also can specify another library which will maintain history but address will not be changed. thanks

Upvotes: 1

Views: 905

Answers (1)

Crazyleopard
Crazyleopard

Reputation: 76

If you'd like to be able to use the Back button, then no. History is stored when doing a page load or changing the location hash.

Upvotes: 1

Related Questions