JQuery Mobile Refresh Previous page On the back button

This code was used to work in JQM to delete previous pages from the DOM, so that when you click "back" it updates the contents of the previous page.

$('div').live('pagehide', function(event, ui) { $(event.target).remove(); }); 

However, this happened in the last jQuery update, because "$ (). Live" was deprecated, and I could not get it to work using "on" or "bind" with the updated parameters.

Has anyone found a working solution for this?

UPDATE:

I cannot use "document.location" because I cannot display specific pages in the "Back" stack.

For example, if I go to the "submit page", and when it is sent, I simply throw History.Back (); and it brings you back to the updated "details page". I don’t want them to click “Back” in the navigation bar and return to the “send page” page again, since the item cannot be sent twice. There are reasons why I don’t use a dialog or popup for this, but that would be too long to explain.

I tried:

 $(document).on("pagehide", "#PageId", function () { $(event.target).remove(); }); 

And it does not work completely, it changes the URL path when I issue History.Back (); but the page remains on the submit page. When I used the code $ (). Live, it worked fine. Maybe "on" is not a good replacement?

+4
source share
2 answers

William, you forget the event parameter.

If you want to use it globally to update all previous pages to "back", you can use "div" instead of "#PageId". Simply put, this is in your javascript for your main page.

 $(document).on("pagehide", "div[data-role=page]", function(event){ $(event.target).remove(); }); 
+3
source

This should work:

 $(document).on("pagehide", "#[pageID]", function() { // your code here }); 
+3
source

All Articles