Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwAl doesn't disappear on back navigation #231

Closed
girishbr opened this issue Dec 11, 2014 · 5 comments
Closed

SwAl doesn't disappear on back navigation #231

girishbr opened this issue Dec 11, 2014 · 5 comments
Labels

Comments

@girishbr
Copy link

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?

@josephfraser
Copy link

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.

@nitishmehta
Copy link

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;
}
};

@nitishmehta
Copy link

You can check reference code here -- #236

@t4t5 t4t5 added the bug label Jan 15, 2015
@t4t5
Copy link
Owner

t4t5 commented Sep 8, 2017

As the pull request says, just use swal.close()

@t4t5 t4t5 closed this as completed Sep 8, 2017
@MasadAshraf
Copy link

MasadAshraf commented Apr 2, 2018

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");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants