Creating templated/persistant header/footer template in jQuery Mobile and PhoneGap

后端 未结 6 503
傲寒
傲寒 2020-12-02 07:27

I\'m diving into writing a mobile app with jQuery Mobile/PhoneGap. I\'m using this sample template to start from, which uses HTML/JS to create the pages. Rather than have al

6条回答
  •  Happy的楠姐
    2020-12-02 08:04

    Don't use pageinit, the events that you should listen for are pagecreate and pageshow, pagecreate gets called the first time a page is loaded, but not when you navigate back to the page, e.g. on back button. Whereas pageshow fires everytime a page is shown, so just bind a live listener to the pageshow event for every page where you add your footer (assuming your footer may change, otherwise use pagecreate).

    I have a longer example that shows you how to bind to the event properly in another question: https://stackoverflow.com/a/9085014/737023

    And yes a great solution is just to use a PHP/CF include, which is what I use instead of JS.


    EDIT My bad, seems pageinit is now used instead of pagecreate (see here), but it still stands that pageshow fires every time a page is shown - so you can use those as you need

提交回复
热议问题