Hybreeder Hybreeder - 1 year ago 1086
jQuery Question

How to redirect page after click on Ok button on sweet alert?

I am able to display sweet alert after the page refresh but i have to click on Ok button which i am getting on sweet alert to redirect the page.Please help me in this.

echo '<script type="text/javascript">';
echo 'setTimeout(function () { swal("WOW!","Message!","success");';

echo '}, 1000);'
echo 'window.location.href = "index.php";';
echo '</script>';

Answer Source

To specify a callback function, you have to use an object as the first argument, and the callback function as the second argument.

echo '<script>
    setTimeout(function() {
            title: "Wow!",
            text: "Message!",
            type: "success"
        }, function() {
            window.location = "redirectURL";
    }, 1000);