JQM (jQueryMobile) Push last page out of DOM on changePage()
Not exactly knowing your markup I am guessing you are triggering changePage()
manually. If that is the case, you could wire up one of the events listed here.
pageshow
Triggered on the page being shown, after its transition completes.
$('div').live('pageshow',function(event, ui){
$(ui.prevPage).remove();
});
Phill Pafford
Love development with PHP/Symfony/PHPStorm, iOS, PostgreSQL, Linux flavor Ubuntu, jQuery/Mobile, Foundation CSS, GitFlow AVH and HTML5 Personal Projects are Crypto Currencies, Home Automation, Mobile development, SMS/MMS and DIY electronics via Make and Hack A Day https://keybase.io/phillpafford https://onename.com/phillpafford #bitcoin: https://www.coinbase.com/phillpafford #DogeCoin: D67fwUKwKQQeL9pdbZmbWcevuAYW8XPqyz
Updated on June 25, 2022Comments
-
Phill Pafford almost 2 years
I notice that the page that I was just viewing is still in the DOM. Is there a way to remove the last page viewed after I transition to the new page using changePage()?
I have disabled all the back navigation as I don't want the use to go back to the last page when transitioning to the new page(s).
Any suggestions?
Flow of the site:
- main page-> fill out info->submit on changePage()
- next page-> fill out more info-> submit on changePage()
- etc...
Once the page has been submitted I don't need it anymore
UPDATE:
Here is the first page:
<div data-role="page" id="first_page" data-theme="z" data-backbtn="false" data-url="first_page" class="ui-page ui-body-z">
It appends something to this when adding a new page:
<div data-role="page" id="next_page" name="next_page" data-theme="z" data-title="next_page" data-url="getNextPage.php?page=next_page" class="ui-page ui-body-z">
Calling the live() like this:
// pageName[index] = next_page $('#'+pageName[index]).live('pagecreate',function(event, ui){ $(ui.prevPage).remove();
using changePage() like this:
$.mobile.changePage('getNextPage.php?page='+pageName[index],'slide',false,false);
-
Phill Pafford about 13 yearsyep that's what I'm doing now. What is the trash part?
-
Phill Pafford about 13 yearsupdated my question w/ code example, but implementation of your suggests works in the demo but not my project. Would I pass the prevPage id/name to the remove()?
-
Mark Coleman about 13 yearsInstead of registering the
.live()
against an #id, try placing the.live()
against any div that isdata-role="page"
$('div[data-role="page"]').live('pageshow',...
, and try thepageshow
instead ofpagecreate
-
Phill Pafford about 13 yearsHmm that does work in removing the prevPage but pageShow breaks my page functionality as I'm adding custom validation/page rendering of elements before the page is shown. What I'm doing is loading each page from an ajax call so only one page is in memory
-
Mark Coleman about 13 yearshmmm since you have an array of
id
s, maybe in yourpagecreate
simply do$('#'+pageName[index]).remove()
? -
Phill Pafford about 13 yearsthat works to remove the prevPage but now the current page doesn't load as it's using pagecreate() instead of pageshow, ugh.....
-
Phill Pafford about 13 yearsAfter some more testing I found the in the method you offer that ann dialogs will trigger this event as well, remove needed code for functioning pages
-
OptimusCrime almost 10 yearsI wish that I could upvote this twice. Thanks a billion!