1

When users log into my jQuery Mobile application and press the automatically generated back button, they go back to the login screen. How do I prevent this effect?

I tried to use this code to prevent caching (which I found from this question: How does one disable Caching in jQuery Mobile UI).

jQuery('div').live('pagehide', function(event, ui){ var page = jQuery(event.target); if(page.attr('data-cache') == 'never'){ page.remove(); }; }); 

This code does prevent caching. However, it breaks all the popup, multiple select option boxes in my forms for some reason, which rely on a pagehide event. Hence, I cannot use it.

What is a reliable way to prevent the user from going to the login screen after logging in and clicking back?

8
  • you can use your cache to check if the user is logged on every page and if he is on login, you redirect to home page Commented Apr 7, 2012 at 19:00
  • Thank you, how do I check if a user is logged in on every page using my cache? Commented Apr 7, 2012 at 19:01
  • know how to use cache on jQuery? Commented Apr 7, 2012 at 19:02
  • oh is there an API for this? is this built into jQM? Commented Apr 7, 2012 at 19:04
  • how do you search for a authorized user? Commented Apr 7, 2012 at 19:06

1 Answer 1

2

The problem isn't with caching. Its the way JQM uses history.replaceState to keep track of navigation in an ajax environment. Read more >> http://jquerymobile.com/demos/1.1.0-rc.2/docs/pages/page-navmodel.html

You could replace the automatically generated back button with your own back button. i.e.

<div data-role="header"> <a data-role="button" data-icon="arrow-l" class="back">back</a> <h1>Page after login</h1> </div> 

Then bind a click to that button to use window.history.go(-2) to navigate back 2 pages in your history. i.e.

$(document).delegate('.back','click',function(){ window.history.go(-2); });​​​​​​​​​​​​​​​ 

Also note that by default a dialog page does not get tracked in JQM's ajax history system. So that if you had some type of ajax login system that enclosed in a dialog page it would not be inserted into the history. And your automatically generated back button would work just fine. This is assuming you are not disabling ajax. Good luck David I hope that helped!

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! 1. Does this back button automatically appear when needed? 2. Why go back 2 pages in history instead of 1?
No I was suggesting you create that back button. I am going back 2 pages so that it skips the login page. I guess you could just make it a link to a certain page also. I was just showing how you could skip the last page in history with a back button.
When you say "automatically generated back button" are you using data-back-btn="true"?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.