Back button problem after redirect detail
The problem happen when you want to redirect a page to another page in jquery mobile and then user have no way to get back to previous page, what we need to navigate to previous page via back button. Here is the way you usually use to redirect a page to a extenal page
window.location.href = "page2.html";
And the problem happen, you have no way to get back with back button of browser.
Solve the back button problem in jQuery mobile redirection
We have 2 ways to solve this issue[ordered_list style=”decimal”]
- Capture the navigation event and control the previous page manually
- Re-use the click event of jquery mobile for A tag
The option (1) will make the problem much more complex since we have to control the previous and the next page history. jQuery mobile already control them for us via external rel of tag a. Let ‘s implement a hidden a tag to handle the event like this.
<a id="hidden-redirection-tag" href="#" rel="external" style="display:none;">hidden link</a>
$("#hidden-redirection-tag").attr("href", "page2.html"); $("#hidden-redirection-tag").click();