php重定向前的sweetalert

php重定向前的sweetalert,php,redirect,sweetalert,Php,Redirect,Sweetalert,我试图在登录时自动重定向之前设置sweetalert2,如果用户未登录,但它仅出现一秒钟,重定向立即启动,如何设置为等待用户单击 我的实际代码: <?php session_start(); if ($_SESSION[logged] != 'yes') { echo ' <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <link r

我试图在登录时自动重定向之前设置sweetalert2,如果用户未登录,但它仅出现一秒钟,重定向立即启动,如何设置为等待用户单击

我的实际代码:

<?php
session_start();
if ($_SESSION[logged] != 'yes') { 
echo '
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<link rel="stylesheet" href="stylesheets/sweetalert2.css">
<script src="javascripts/custom/sweetalert2.min.js"></script>
<script>
$( document ).ready(function() {
    swal("Oops...", "Not logged!", "error");
    document.location.href="/login.html"
});
</script>';
exit; 
}
?>

您可以添加一个计时器,就像这样,它会等待5秒钟,然后使用重定向

  $( document ).ready(function() {
    alert("Oops...Not logged! error");
    var millisecondsToWait = 5000;
    setTimeout(function() {
       document.location.href="/login.html"
    }, millisecondsToWait);

  });

使用swal代替警报。

您可以添加一个计时器,就像这样,它会等待5秒钟,然后使用重定向

  $( document ).ready(function() {
    alert("Oops...Not logged! error");
    var millisecondsToWait = 5000;
    setTimeout(function() {
       document.location.href="/login.html"
    }, millisecondsToWait);

  });

使用swal代替警报。

Sweet alert具有回调功能:

swal({
    //options
}, function(isConfirm) {
     document.location.href="/login.html"
});

Sweet alert具有回调功能:

swal({
    //options
}, function(isConfirm) {
     document.location.href="/login.html"
});

您需要的是重定向线路的延迟

   setTimeout(function () {
       window.location.href = "/login.html"; //will redirect to your page after 2000 ms
    }, 2000);
资料来源:
您需要的是重定向线路的延迟

   setTimeout(function () {
       window.location.href = "/login.html"; //will redirect to your page after 2000 ms
    }, 2000);
资料来源: