nKognito
nKognito

Reputation: 6363

Getting parameters after page refresh with history.js

I moved from jquery.address library to history.js and now facing the problem with getting parameters in case of page's full refresh. The code looks like:

function onStateChange(updateSearchQuery) {
    var params = History.getState();
    if (params.data.create != null) {
        editedId = 0;
    }   
    else if (params.data.id) {
        editedId = params.data.id;
        show();
    }
    else {
        currentPage = parseInt(params.data.page) || 1;
        searchQuery = params.data.query || '';
        if (updateSearchQuery)
            $('input[name="query"]', '#search-form').val(searchQuery);
        showList();
    }
};
History.Adapter.onDomLoad(function() {
    onStateChange(true);
});

It works fine while changing the state programatically i.e. with History.pushState, but I want to handle the situation when user refreshes the page with url: www.test.com/somepage?id=1 - is there any built-in methods or ways to get this id parameter?

Thank you

Upvotes: 0

Views: 2986

Answers (1)

Carlos Nuñez
Carlos Nuñez

Reputation: 470

You should use the function pointed here.

How can I get query string values in JavaScript?

Pass "id" as the value.

Upvotes: 1

Related Questions