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

  • Home
  • SEARCH
  • 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 8798405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:05:27+00:00 2026-06-14T00:05:27+00:00

I have two page written in the single page template way. Login.html has <script

  • 0

I have two page written in the single page template way.

Login.html has <script src="login.js" /> in his <head></head> and this is like:

$(document).on("pageinit", "#loginPage", function(){
   $("#loginBtn").on("tap", function(){
      // if you are already authenticate or login success...
      $.mobile.changePage("Main.html");
   });
});

Main.html has is <script src="main.js" /> in his <div data-role="page" id="main"></div> and this is like:

$(document).on("pageinit", "#main", function(){
//if not authenticated go to login
   $.mobile.changePage("Login.html");

    callJsonService();

$("#btnLogout").on("tap", function(){
            //do logout operatio and go back to login
    $.mobile.changePage("Login.html");
}).on("vmousedown", function(){
    $(this).addClass("tapped");
}).on("vmouseup", function(){
    $(this).removeClass("tapped");
});

If you navigate back and forward these 2 pages, every time you visited the page, the event bound with on() are fired two times, then three times, then four times etc. etc.

Why is this happening? It is due to the ‘pageinit’ event? or it is not correct to put the main.js inside the div with data-role=page?

  • 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-14T00:05:28+00:00Added an answer on June 14, 2026 at 12:05 am

    Don’t load JS within your <div data-role="page"/> it will fire multiple times, I like to bind an on listener to the document root in a js file that I include on each page

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

    Now place some sort of data variable or class on your <div data-role="page" data-pageid="foo"/> to distinguish between your different pages, now you have two variables to branch your code on

    1. event.type = pageinit/pageshow: the first fires once only for each
      page, latter will fire on first load and re-fire if you press back
      and navigate back to the page

    2. $(this).data(‘pageid’) = whatever you want, in this case when page foo fires either event you can handle appropriately, no surprises

    See my older answer: https://stackoverflow.com/a/10542821/737023 for more detail

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

Sidebar

Related Questions

I have an ASP.Net application running under IIS 6. A simple page has two
I have an HTML page where there are two Textboxes and a Button. And
I am trying to change the HTML image src using Javascript. I have two
I have written a code for a login page and user page. When the
I have written a very simple Chrome extension. It consists of this background page:
lets assume we have this table called visits and it has two fields id
Default3.aspx This is my first page. in which i have two textbox and one
I have two carousels on one page but unfortunately they copy each other. http://jsfiddle.net/seanjacob/tB6y5/
I have two controls on a page, one is a search entry and submission
I have two forms on one page and want to have the input boxes

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.