Zathrus Writer
Zathrus Writer

Reputation: 4331

jQuery mobile hiding initial page instead of removing it

I've been searching for a way to remove the initial page container after jQuery mobile loaded the next page content via $.mobile.changePage(...)

What I'm experiencing is that this initial DIV element, created when the page is first shown will always remain on the page - and will only be hidden after calling $.mobile.changePage(...)

I need this initial page container to be removed instead, since some old data reside there that should be reset on first page change.

Anyone has a solution? Been searching the web for it but to no avail.

I have also tried to do $('#first-page').remove() after I called $.mobile.changePage(...), but that will remove the initial page and make the new loaded page hidden!

EDIT: solved by clearing up the initial DIV using .html("")

Upvotes: 2

Views: 2775

Answers (3)

Blundell
Blundell

Reputation: 76506

I did:

 $.mobile.changePage('login.html', {changeHash:false});

changeHash (default: true) Type: Boolean Decides if the hash in the location bar should be updated. This has the effect of creating a new browser history entry. It also means that, if set to false, the incoming page will replace the current page in the browser history, so the page from which the user is navigating away will not be reachable via the browser's "Back" button.

Upvotes: 0

sgliser
sgliser

Reputation: 2071

I take it that you are dynamically creating these pages. There is a hidden method in the API, but you can apply it to any page and then upon that page's exit, it will be removed.

$.mobile._bindPageRemove

So, it might look like this

newpage.attr( "data-" + $.mobile.ns + "external-page", true ).one( 'pagecreate', $.mobile._bindPageRemove );

NOTE: Since this is a hidden method, it is part of the hidden API and could be subject to change without notice upon upgrade. Test carefully upon upgrade if you use this.

Upvotes: 1

shanabus
shanabus

Reputation: 13115

You could just make next page load without ajax, this should remove the initial page.

data-ajax="false"

Hope this helps!

Upvotes: 1

Related Questions