I'm trying to close a popup / dialog when a user presses a button inside the popup, and navigate to another page (single page application, multiple "pages"). jQM 1.4.0
If I tap the YES-button inside the popup, it will navigate to #page3 wich I want but then jump back to the startpage. If I comment out the .popup("close"); it works, but I need to close the popup before I do stuff. What is wrong here?
js
$("#popupyes").on("tap", function(e)
{
$("#popupDialog").popup("close"); // <---- doesn't work
//call some js-function before navigate to #page3
});
html
<a href="#popupDialog" data-rel="popup" data-position-to="window" data-transition="pop" class="ui-btn ui-corner-all ui-shadow ui-btn-a">Button</a>
<div data-role="popup" id="popupDialog" data-overlay-theme="a" data-theme="a" data-dismissible="false" style="max-width:400px;">
<div data-role="header" data-theme="a">
<h1>Head</h1>
</div>
<div data-role="main" class="ui-content">
<h3 class="ui-title">Text.</h3>
<p>Text?</p>
<a href="#page3" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-a">No</a>
<a href="#" class="ui-btn ui-shadow ui-corner-all ui-btn-inline ui-btn-icon-right ui-icon-delete" data-rel="back">Abort</a>
<a id="popupyes" href="#page3" class="ui-btn ui-shadow ui-corner-all ui-btn-inline">Yes</a>
</div>
</div>
Update
I can use $("#popupDialog").hide();
But then it's still in memory, only hidden... or wait, will it terminate by itself after a while?
You can simply listen to popupafterclose
to call any function after popup is completely closed.
$(document).on("pagecreate", function () {
$("#popupID a").on("tap", function () {
/* do something */
$("#popupID").popup({
afterclose: function () {
/* do something */
}
}, "close");
});
});
来源:https://stackoverflow.com/questions/22534385/close-popup-and-navigate-to-another-page-in-jquery-mobile