How to clear or change the navigation history of Jquery Mobile? -
i have phonegap app using jquery mobile. @ page, cannot let user go last page visited.
the pages order this:
(1)index -> (2)listing items -> (3)form submited -> (4)sucess page what need: want clear history when user @ page 4 , set page 1 last , visited in case of user tries go back. maybe that's not totally possible, accept suggestion.
i imagine jquery mobile stores navigation history in kind of array, , hope can find that. in advance!
edit: i'm using multi-page template, single html page, divs works pages managed jquery mobile.
basically have 2 history "pots" need tamper with. browser , jqm.
jqm urlhistory
can modify jqms urlhistory easily. jqm code:
urlhistory = { // array of pages visited during single page load. // each has url , optional transition, title, , pageurl // (which represents file path, in cases url obscured, such dialogs) stack: [], // maintain index number active page in stack activeindex: 0, // active getactive: function () { return urlhistory.stack[urlhistory.activeindex]; }, getprev: function () { return urlhistory.stack[urlhistory.activeindex - 1]; }, getnext: function () { return urlhistory.stack[urlhistory.activeindex + 1]; }, // addnew used whenever new page added addnew: function (url, transition, title, pageurl, role) { // if there's forward history, wipe if (urlhistory.getnext()) { urlhistory.clearforward(); } urlhistory.stack.push({ url: url, transition: transition, title: title, pageurl: pageurl, role: role }); urlhistory.activeindex = urlhistory.stack.length - 1; }, //wipe urls ahead of active index clearforward: function () { urlhistory.stack = urlhistory.stack.slice(0, urlhistory.activeindex + 1); } }; so of above functions available , can called example:
$.mobile.urlhistory.clearforward(); to monitor history, put somewhere , listen pagechange (once transitions done) see inside urlhistory:
$(document).on('pagechange', 'div:jqmdata(role="page")', function(){ console.log($.mobile.urlhistory.stack); }); from there can start see should in history , clean need.
i'm using lot own navigation layer modify stored in urlhistory , should not stored. sync-ing browser difficult part...
on sync-ing browser:
in navigation layer i'm removing double entries urlhistory, there page go (and not two), when click browser button. in case, presumable have 4 entries in browser history, if remove 2 entries jqm urlhistory, have two pages "not got to" when button clicked. if browser history looks this:
www.google.com www.somepage.com www.your_app.com = page1 page2 page3 page4 and remove page2 , page3, clicking back-button should result in:
1st back-click = page4 > page1 2nd back-click = page1 > www.somepage.com [because removed page3] 3rd back-click = www.somepage.com > www.google.com [because removed page2] a theoretical workaround be:
- keep counter how "deep" go page
- remove pages jqm urlhistory , "jump" value = counter-removedpages
- on next browser click, jump x window.history(back) , let 1 jqm transition pass. url unwind page4>page3>page2>page1 in 1 step , allow jqm single transition page4 page1
- check what's in urlhistory , clean after "triple back"
beware not optimal solution , have consider lot of things (user clicks somewhere else before going etc). tried forever work in more complicated setup , stopped using it, because never worked should. simpler setup may work.
Comments
Post a Comment