Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a popup on pageshow in Jquery-Mobile

It appears that I can't open a popup in a method called with the event "pageshow". I know that my code isn't wrong because the popup is opened when I click on the button... And I checked in Firebug there's no error messages. Here's the code :

HTML :

<div data-role="popup" id="myPopup">
    ... my elements
</div>

JS :

$('#p_guarantee').live('pageshow', function(){
    $('#myPopup').popup('open');
});

Anybody knows if there's something special to do ? I would be soo grateful if you can solve my problem :)

Thanks in advance !

like image 271
user1741088 Avatar asked Oct 12 '12 12:10

user1741088


1 Answers

Following our discussion in comments, you can resolve this using setTimeout() function after the pageChange event is fired. I suspect this could be because the page is first rendered and improved and only after this, elements with special meanings (like popups) get their events bound.

You can also try to remove the data-role="popup" from your popup DIV completely and essentially do this:

<div id="myPopup">
    ... my elements
</div>

$('#p_guarantee').live('pagechange', function(){
    $('#myPopup').popup();
    $('#myPopup').popup('open');
});

... and see if that works for you.

like image 183
Zathrus Writer Avatar answered Nov 12 '22 19:11

Zathrus Writer