last day (15 days later) » 

9:30 PM
0
Q: Dynamically Creating and Removing Pages in jQuery Mobile 1.4.4

dartfishAfter I create some page dynamically and insert it into body, what should I run to let the jquery mobile know that this page is new in order to initialize (or whatever jquery mobile needs to do with it)? How to remove the page dynamically (and let jquery mobile know, if that is needed)? I am awa...

 
If you inject a page into Dom, you don't have to initialize it, JQM will initialize it before showing. Removing a page from Dom, doesn't remove it from navigation history, hence, you'll need to manipulate navigation on pagecontainerbeforetransition.
 
When JQM initialize it before showing, can this be a performance problem? If so, I would prefer to initialize this page long before going to it. Actually I have bunch of pages which I will insert and I would like to initialize them all at the same time.
 
In this case call .page() however I don't think it's going to affect performance. All pages static and dynamic are initialized before being shown. pagebeforecreate.
 
Thanks! You can put all that into an answer so I can accept it.
 
I'll prepare a comprehensive answer.
btw, what do you mean by "How to remove the page dynamically (and let jquery mobile know, if that is needed)?" Pages can be removed, but what do you mean by needed?
 
9:30 PM
It is easy to remove div from the DOM that defines the page. But then, is there something that I should do to tell JQM what I just did? Maybe JMQ needs to know that to clean some stuff in the background (I am just assuming)? Or maybe JQM just provides some method to remove a page from the DOM that I should just use?
 
in this case, changeHash: false is what you. This will not register page in history "history.replaceState()"
so both DOM and history will be clean once the page is removed
i'm preparing an answer, I just want to make sure that I answer all you concerns
@dartfish
 
 
1 hour later…
11:01 PM
I was not initially concerned about history. So, I guess it is enough to do something like $('#mypage').remove()
in your fiddle, what is up with .enhanceWithin() ?
.enhanceWithin() should be used instead of .page()?
 
11:35 PM
@dartfish you can easier use .enhanceWithin() to create page's contents but not page itself.
.page() will create page and contents.
 
Then I need just .enhanceWithin()
I think you have answered everything what I need.
I have one more question that is not directly related to this one
 
Regarding history, if you move to pageX to pageY and remove PageX. When you hit back button, you'll be moved to pageX even if it's removed
From DOM, it still exists in history.
Sure, what is it
 
I know about that history thing. I am creating application with phonegap, so I will not have 'browser' button. That's why I am not concerned
 
Not even data-rel=back buttons? They act like back button
 
oh, you are right. :) i will use that
is it possible to remove something for history that was several pages ago?
*from
 
11:52 PM
@dartfish you can remove entry from $.mobile.navigate.history.stack but I don't think you can remove it from browser's navigation history
Because jQM uses history.replaceState() on navigation. When changeHash is false, it doesn't. Not even in jQm history stack.
 
that's file. i will know consequences then i use buttons such as data-rel=back.
*fine
i know that i can pre-load page with pagecontainer.load(). but i think i cannot use that to load several pages at once. can i do that? is there some another function from JQM to load more than one page with one call to server?
 
No, you can't load external multi-page file, in fact, you get only first page div in any external file
Btw, external files or single page model, the pages get removed once hidden.
 

  last day (15 days later) »