我正在尝试在登录时自动重定向之前设置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;
}
?>
答案 0 :(得分:0)
你可以添加一个计时器,就像这个,等待5秒,然后使用重定向
$( document ).ready(function() {
alert("Oops...Not logged! error");
var millisecondsToWait = 5000;
setTimeout(function() {
document.location.href="/login.html"
}, millisecondsToWait);
});
而不是警报只是使用swal。
答案 1 :(得分:0)
甜蜜警报有回调功能:
swal({
//options
}, function(isConfirm) {
document.location.href="/login.html"
});
答案 2 :(得分:0)
你需要的是延迟重定向线
setTimeout(function () {
window.location.href = "/login.html"; //will redirect to your page after 2000 ms
}, 2000);