Javascript sweetalert关闭后重定向

Javascript sweetalert关闭后重定向,javascript,php,html,jquery,Javascript,Php,Html,Jquery,我想在sweetalert模式超时关闭后被重定向到另一个页面。 我正在使用以下代码。模式显示,计时器结束后关闭,但新页面未重定向 $('#with-timer').on('click', function () { var timerInterval; swal({ title: 'Auto close alert!', html: 'I will close in <strong>2</strong> seconds.',

我想在sweetalert模式超时关闭后被重定向到另一个页面。 我正在使用以下代码。模式显示,计时器结束后关闭,但新页面未重定向

$('#with-timer').on('click', function () {
    var timerInterval;
    swal({
      title: 'Auto close alert!',
      html: 'I will close in <strong>2</strong> seconds.',
      timer: 2000
    }).then(function (result) {
      if (result.dismiss === swal.DismissReason.timer) {
        window.location.href = "index.php";
      }
    });
  });
$('#带计时器')。打开('单击',函数(){
var时间神经;
游泳({
标题:“自动关闭警报!”,
html:“我将在2秒后关闭。”,
计时器:2000
}).然后(函数(结果){
if(result.dismise==swal.DismissReason.timer){
window.location.href=“index.php”;
}
});
});
有什么解决这个问题的建议吗

谢谢。

尝试使用
replace()
而不是
href()

将代码更改为

.then(function (result) {
      if (result.dismiss === swal.DismissReason.timer) {
        window.location.replace = "index.php";
      }

看起来你把sweetalert和sweetalert2混在一起了。它们有不同的API。看起来sweetalert2会告诉您警报被解除的原因,因此我将使用它来回答这个问题,尽管它使用
swal.fire
来打开警报

下面是一个工作示例:

$('#带计时器')。打开('单击',函数(){
var时间神经;
喷火({
标题:“自动关闭警报!”,
html:“我将在2秒后关闭。”,
计时器:2000
}).然后(函数(结果){
if(result.dismise==swal.DismissReason.timer){
window.location.href=”https://stackoverflow.com";
}
});
});


打开模式
您使用的是什么SweetAlert?SweetAlert、用于引导的SweetAlert或SweetAlert2。确切版本?我让您的代码使用SweetAlert2,但必须将
swal({…
更改为
swal.fire({…
)。可能您正在使用SweetAlert2的dissmiss reason功能和另一个不支持此功能的SweetAlert2变体?尝试使用document.location=“index.php”;这与php有什么关系?