frequent
frequent

Reputation: 28503

how can I prevent the user leaving the page when hitting the browser back button in Jquery Mobile?

Just wondering.

I have a page in Jquery Mobile which uses a popup that opens as a fullscreen page on smartphone displays:

Desktop/Tablet:

enter image description here

Smartphone:

enter image description here

Problem is, if the user views the page on smartphone, this looks like a real page. When the user hits the "back" button I provide, I'm just closing the popover. However, if the user hits the browser back button, he's leaving the page, because he never went a page down in the history.

Question:
Since I can't disable the browser back button, is there another way to create a browser history entry when the popover opens, so when the user presses the back button, I'm simply closing the popover and the browser history is back on the initial page vs. going "-1". If there are other workarounds to achieve this I'd also appreciate any suggestions.

Thanks!

Upvotes: 0

Views: 722

Answers (2)

LOZ
LOZ

Reputation: 1177

Try adding a live Vclick.

or

you could try disabling the class ui,

Example:

class="ui-disabled"

Upvotes: 0

Silver Gonzales
Silver Gonzales

Reputation: 734

Maybe what you can do is add the popover as a dialog page if the webpage is opened from a smartphone (you can use user-agent to check for this). You might want to check http://jquerymobile.com/test/docs/pages/page-dialogs.html That way it will be added to the browser history.

Upvotes: 3

Related Questions