Want to show a dialog message in jQuery mobile when it is loaded

In jQuery mobile, I want to show a dialog message on my home page ( index.html

) when this page is first loaded. However, if a user navigates to different pages on my site and returns to mine index.html

, I don't want to show the dialog.

I am thinking about using a method pageshow

or pagebeforeshow

and checking an object prevPage

. Is there any other good way to do this?

+3


source to share


2 answers


Use the pageinit event , it will only fire once. It couldn't be easier than this.

JsFiddle example: http://jsfiddle.net/Gajotres/e9RcT/



$(document).on('pageinit', '#index', function(){       
    alert('This event will trigger only once!');
});

      

To check this, go to the second page and then return.

+5


source


Loading into the DOM ensures that whatever you want to do only happens when the first page is initialized:

$(document).ready(function(){
  // do stuff here
});

      



source: http://jquerymobile.com/test/docs/api/events.html

+2


source







All Articles