Sweetalert2:在新选项卡中打开外部 link 是

Sweetalert2: open external link in new tab on Yes

我使用 SweetAlert2 实现了这个调查弹出窗口。浏览 5 次后,页面加载 3 秒后弹出“是 - 否”问题。

问题是我想在新标签页/window 中打开外部 url。我已经试过 window.open(survey_url, '_blank');,但它在 IE 中有问题。用户必须允许弹出窗口,似乎 link 未打开。

在sweetalert2上下文中有没有更好的解决方案?我的意思是有一个带有 link 之类的简单按钮?

  $(document).ready(function($) {
    var survey_delay = 3000; // milliseconds
    var survey_delay_pageviews = 5;
    var survey_title = "This is a title!";
    var survey_text = "Would you be willing to say Yes?";
    var survey_url = "http://google.com";

    if(!localStorage.getItem("survey_answered")) {
      var pageviews = (+localStorage.getItem("page_views") || 0) + 1;
      localStorage.setItem("page_views", pageviews);

      if(pageviews >= survey_delay_pageviews) {
        setTimeout(function() {
          swal({
            title: survey_title,
            text: survey_text,
            type: "success",
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes',
            cancelButtonText: 'No'
          }).then(function(result) {
            localStorage.setItem("survey_answered", "true");
            window.location.replace(survey_url);
          }).catch(function() {
            localStorage.setItem("survey_answered", "true");
          });
        }, survey_delay);
      }
    }
  });

通过将默认按钮替换为 link 按钮和 _blank 目标来解决。在我的 }, survey_delay); 行之前添加:

  setTimeout(function () {
    $("button.swal2-confirm").replaceWith('<a target="_blank" class="swal2-confirm swal2-styled" style="background-color: rgb(48, 133, 214); border-left-color: rgb(48, 133, 214); border-right-color: rgb(48, 133, 214);" href="' + survey_url + '">Yes</a>');
    $("a.swal2-confirm").click(function () {
      localStorage.setItem("survey_answered", "true");
      swal.close()
    })
  }, 400);