1

I'v a site with jQuery Mobile multi page layout.

After AJAX login from #Login page user redirects to #CustomerDashboard or #AdminDashboard despending on the user type.

$.mobile.changePage("#CustomerDashboard", { changeHash: true });

My issue is that when user press back button the #Login page will be again displayed, and user can again login.

How can I prevent this?

if I removed the Login page using $("#Login").remove(); back button still shows the login page renderd!

#Login page cannot be removed fully because when user signs out, i need to show the login form again. This can be prevented by saving the Login page HTML and injecting back to DOM after signout.

But even though Login page is removed it remains in the browser history.

if I detect an active session exists on login page and redirects the user back to dashboard, user will not be never reach the page/site that he visited before coming to my site

Mithun Sreedharan
  • 49,883
  • 70
  • 181
  • 236
  • hide the Login id using jquery – Sudharsan S Mar 17 '14 at 09:00
  • When user clicks back, he will see the login page. However if you want to handle the above case, I suggest you use session. – madi Mar 17 '14 at 09:02
  • 1
    You need to remove login page from `$.mobile.urlHistory.stack`. Try this after moving from login page. `$.mobile.urlHistory.stack.splice(0,1)`. Where `0` is the index of `login` page history inside history array. This is in case `login` page is the first page to be shown when you startup jQM framework. – Omar Mar 17 '14 at 09:05
  • 1
    or use this method http://stackoverflow.com/questions/19520101/stop-showing-page/19522643#19522643 – Omar Mar 17 '14 at 09:18
  • 1
    `$.mobile.urlHistory` is not defined for jQM 1.4.0. Instead `$.mobile.History` is there but firebug shows it as constructor function in red color – Mithun Sreedharan Mar 17 '14 at 09:25
  • true, this was used in earlier versions. It's changed in 1.4, i'll look it up. but anyway, you can utilize `pagebeforechange` as in the answer above. – Omar Mar 17 '14 at 09:31
  • it's `$.mobile.navigate.history.stack` for jQM => 1.4 – Omar Mar 17 '14 at 09:36

1 Answers1

0

Rudimentary way, simply force the user off the page if they try to return to it:

$(document).on('pagebeforeshow', '#login-page', function() {
    if(login === 1) {//login condition
        $.mobile.changePage("#dashboard-page");
    }
});
andrewthong
  • 101
  • 2