user1741088
user1741088

Reputation: 55

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 !

Upvotes: 5

Views: 9327

Answers (3)

Abdul-malik musah
Abdul-malik musah

Reputation: 1

if you want to use jquery mobile for the popup first create a link with data-rel popup and href pointing to the id of the container containing the pop element. the div should have data-role popup

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
example
<a href="#pop" data-rel="popup>click me</a>
<div data-role="popup" id="pop">
... pop up elements go here ...
</div>

Upvotes: 0

Zathrus Writer
Zathrus Writer

Reputation: 4331

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.

Upvotes: 6

Pablo
Pablo

Reputation: 2854

I see no problems in your code. For which platform are you developing?

Try with the code in this example: http://jsfiddle.net/hhejq/1/

Upvotes: 0

Related Questions