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

when i click ok button of sweet alert.. send to another page #199

Closed
fabianchoxD opened this issue Nov 12, 2014 · 17 comments
Closed

when i click ok button of sweet alert.. send to another page #199

fabianchoxD opened this issue Nov 12, 2014 · 17 comments

Comments

@fabianchoxD
Copy link

i need go to another page after click at ok or error button...my code:

i use a $(document) because i need show the error when the page is loaded

<script> $(document).ready(function () { swal({ title: "Error", text: "wrong user or password", type: "error" }); }); </script>

pls give me a hand ;)

@fabianchoxD fabianchoxD changed the title gl when i click ok button of sweet alert.. send to another page Nov 12, 2014
@varunsridharan
Copy link

i think this can be done using location.href = 'http://google.com'

this should be called at ok / error button click handler;

@t4t5
Copy link
Owner

t4t5 commented Nov 12, 2014

As @technofreaky said, you can redirect using JavaScript. Here's a similar example: #168

@t4t5 t4t5 closed this as completed Nov 12, 2014
@fabianchoxD
Copy link
Author

i can solve it :)

only use window.location.href .. here is the code:

    $(document).ready(function() {
swal({ 
  title: "Error",
   text: "wrong user or password",
    type: "error" 
  },
  function(){
    window.location.href = 'login.html';
});

});
Thank's for help me

@Jpsstack
Copy link

@fabianchoxD Good Job !

@sunilsmith
Copy link

I need to bind a html page within sweet alert. so that when my sweet alert triggered it should show the html page in its body.

@prajesh2u
Copy link

how can i do the alert when user is trying to close browser/tab with SweetAlert? Please help me out..

@MAbdulHalim
Copy link

@fabianchoxD thanks, it works.

@yogesh-mistry
Copy link

yogesh-mistry commented Jun 7, 2017

anyone have any idea about the callback function/event triggered on click of OK button genereated using persistant() function?
Alert::success('Success Message', 'Optional Title')->persistent("Ok");

@cnchg
Copy link

cnchg commented Aug 20, 2017

@fabianchoxD thank you for the solution but it did not work for me. I was able to resolve this issue like this:
swal({
title: "Success!",
text: response.scriptstatus,
type: "success"
}).then(function() {
// Redirect the user
window.location.href = "new_url.html";
console.log('The Ok Button was clicked.');
});

@koolbseit
Copy link

@cnchg many thanks, it's work for me!!!

@grafluxe
Copy link

If you also have a "Cancel" button in your modal, you'll want to confirm that the "OK" button was indeed pressed:

swal({...}).then(okay => {
  if (okay) {
    window.location.href = "...";
  }
});

@jmada
Copy link

jmada commented Mar 23, 2018

swal({
   icon: "error",
  title: "¡Error!",
  showConfirmButton: true,
  confirmButtonText: "Cerrar",
  closeOnConfirm: false
}). then(function(result){
  window.location = "WEREYOUWANTTOGO";
             })

This is my solution for this issue!

@zoom699
Copy link

zoom699 commented Aug 19, 2018

function MesajUyari($mesaj,$text,$icon,$sure,$url){
echo"<script >
swal({
title:"$mesaj",
text:'$text',
icon:'$icon',
button:'Kapat'
});
</script> ";
header("Refresh: $sure; url=$url");
//location.href = 'http://www.alokatalog.com/'
//$gidecekSiteAdres= header('location:'.$_SERVER['HTTP_REFERER']);
}
MesajUyari("Proje Oluşturma Başarılı","Yönlendiriliyorsunuz
Lütfen Bekleyin","success",3,"Sayfa.php");/

@dinukakulatunga
Copy link

@fabianchoxD thank you for the solution but it did not work for me. I was able to resolve this issue like this:
swal({
title: "Success!",
text: response.scriptstatus,
type: "success"
}).then(function() {
// Redirect the user
window.location.href = "new_url.html";
console.log('The Ok Button was clicked.');
});

Thanks!! It worked!!

@sbalasa
Copy link

sbalasa commented Feb 20, 2020

Mine is redirecting to the page directly without even showing the Alert message. Am using Chrome.

       swal({
                title: "App",
                text: "Error: Invalid Credentials, try again !",
                icon: "error",
                closeOnConfirm: false
        }).then(
                function () {
                        window.location.href = 'index.html';
                }
        );

@yvaneee
Copy link

yvaneee commented May 21, 2020

Hi, I'm trying to make swal disappear after 5 seconds so I put a timer: 5000 but when the timer is done, even if the user didn't click the button, it goes to another page. I want to the user to stay on the page if he didn't click the button on swal. Here's my code:

                        Swal.fire({
                            html: "Your tip has been published.",
                            icon: 'warning',
                            showCancelButton: false,
                            confirmButtonText: "See tip",
                            timer: 5000,
                            customClass: {
                                container: 'custom-alert',
                                popup: 'published-tip',
                                actions: 'actions-btn'
                            },
                        }).then(function() {
                            window.location = "/" + data.username;
                        });

@malikbakacak
Copy link

Swal.fire({
text: "Here's a basic example of SweetAlert!",
icon: "question",
buttonsStyling: false,
showCancelButton: true,
allowEnterKey: false,
confirmButtonText: "Ok, got it!",
cancelButtonText: 'Nope, cancel it',
customClass: {
confirmButton: "btn btn-primary",
cancelButton: 'btn btn-danger'
}
}).then(({ isConfirmed }) => { alert(isConfirmed); });

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

No branches or pull requests