Using SwAl in a Jquery Mobile app running in a cordova shell. It works just great but for one small issue.
SwAl is up and the user presses the back button on his Android app. Everything in the background goes one step back but no SwAl - SwAl just stays there for some reason I am not able to figure out.
How do I get SwAl to disappear when an user navigates back on his phone?
Im guessing here. If you show us some code, I might be able to hep more.
for sweetAlert to hide, the page needs to refresh. In a Cordova or JQuery when you press back, the page doesn't refresh, it just changes state, so trying putting an event handler on the back-button/page-change using phonegap and hide sweet alert.
I found a workaround to this. had to make few modification to swal library too.
in my code, I am checking for the back navigation and also if the swal is open or not.
if so , i just close it and prevent the default navigation too.
$(document).on("pagebeforechange", function(e, ob) { //to prevent back navigation
if(ob.options.direction=="back" && swal.isOpen()){
swal.cancelAlert(); //close the swal
e.preventDefault(); //prevent back nav
history.go(1); //avoid hash change
// return false;
}
})
// Closes/Cancel any open sweet alerts
window.swal.cancelAlert = function() {
closeModal();
};
//Check whether the SWAL is open or not.
window.swal.isOpen = function() {
var modal= getModal();
if(hasClass(modal,"showSweetAlert")){
return true;
}else if(hasClass(modal,"hideSweetAlert")){
return false;
}else{
return false;
}
};
You can check reference code here -- https://github.com/t4t5/sweetalert/pull/236
As the pull request says, just use swal.close()
just use this script , its working for me:
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");