Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7916913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:58:39+00:00 2026-06-03T14:58:39+00:00

I have 5 pages – for ease lets say: one.html two.html three.html four.html five.html

  • 0

I have 5 pages – for ease lets say:

  • one.html
  • two.html
  • three.html
  • four.html
  • five.html

When I load each individual page, both pageinit and pagecreate are firing correctly.

The Problem:

When I go from one.html to two.html, pageinit and pagecreate both fire, BUT when I go back to one.html (from two.html), pageinit and pagecreate DO NOT fire.

Why is this and how can I always fire pageinit and pagecreate on page load, as well as navigating through each page?

Update:

For each page I have:

<div data-role="page" id="page-name">

 // content
</div>

To test the order at when things are firing I do:

$(document).on('pagecreate','[data-role=page]', function(){
  console.log('PAGECREATE');
});
$(document).on('pageinit','[data-role=page]', function(){
  console.log('PAGEINIT');
});
$(document).on('pagebeforeshow','[data-role=page]', function(){
  console.log('PAGEBEFORESHOW');
});
$(document).on('pageshow','[data-role=page]', function(){
  console.log('PAGESHOW');
});

How do I use the pagechange to always call the pageinit and pagecreate

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:58:40+00:00Added an answer on June 3, 2026 at 2:58 pm

    You’re checking for the wrong events, pageinit and pageshow are what you should be concerned about.

    pageinit fires everytime a page is loaded for the first time, jQM caches pages in the DOM/memory so when you navigate back from two.html to one.html, pageinit won’t fire (it’s already initialized)

    pageshow fires everytime a page is shown, this is what you need to be looking for when you navigate back from two.html to one.html

    Together you can pull off a lot of clean code, use pageinit for initializing, configuration etc and update your DOM to the initial state. If you have dynamic data on the page that may change between views, handle it in pageshow

    Here’s a good design for larger websites that we use in a production environment:

    1. bind a live event to all pages/dialogs pageinit and pageshow events in some include that is on every page:

      $(document).on('pageinit pageshow', 'div:jqmData(role="page"), div:jqmData(role="dialog")', function(event){

    2. I reference each page with a name: <div data-role="page" data-mypage="employeelist">
      In this live event you can basically have a switch statement for each page “name”, and then check event.type for pageinit/pageshow or both and put your code there, then every time a page is created/shown this event will be fired, it knows what page triggered it and then calls the corresponding code

    3. Now no matter what entry point a user lands on your site, all the handlers for all the pages are loaded. As you may already know, when you navigate to a page, it only pulls in <script/> within the div[data-role=”page”] – ignoring any JS in the <head/>, placing separate JS on each page is a mess and should be avoided in any large site I believe

    4. Try not to use blanket selectors in your jQuery, e.g. $('div.myClass') since this will search all of your DOM which may have more than one jQM page in it. Luckily in the live event handler for pageinit/pageshow mentioned above, this refers to the current page. So do all DOM searches within it, e.g. $(this).find('div.myClass') this ensures you are only grabbing elements within the current page. (of course this isn’t a concern for ids). Note in the pageshow event you can also use $.mobile.activePage, but this isn’t available in the pageinit, so I don’t use it for consistency

    I eventually had too much code, so I built a handler object where each page’s js is included in a separate js file and can register handlers with the live event

    The drawback is that all your js for your entire site is loaded on the first page the user reaches, but minified even a large site is smaller than jQuery or jQM so this shouldn’t be a concern. But if your site really is large I suppose you could look into RequireJS.

    An advantage is you are no longer loading all your JS for each page through AJAX each time the user navigates to a new page. If all your JS is available on entry, you can now put debugger statements and debug much more easily!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two pages and I want to pass data to each other. How
Lets say I have three django model classes - lets call them A, B
the pages have only one variable which changes, and each page only holds one
I have two pages load at beginning, login page and register page. Register page
I have several pages to do with several table on each page. I've got
I have two pages, NonMember.aspx and Member.aspx. If a user comes to the site,
I have two pages, A and B. I want to echo a variable written
I have two pages, on the first page after an event happens I change
I have 3 pages: search.html. search.php, and edit.php I also have new.php which I
I have two pages, Page A and Page B. Both of them have an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.