sweet alert 2 gem 确认框在按确定后重定向到 link

sweet alert 2 gem confirm box redirect to link after pressing ok

我不确定为什么 ok 或 cancel 没有做任何事情,无论如何我想要当有人按 ok 将它重定向到 link

<div class="popup" onclick="sweetalertclick()">
              <p id="center"><%= image_tag "pickup.png" ,width: "80px"%><br>
                <span  onclick="sweetalertclick()"></span>Request a DDS pick u
                </span>
              </p>
            </div>
    <script>
    function sweetalertclick() {
    
    swal({
        title: "Request a DDS",
        text: "Please log in to DDS website to request a pick up, my code is: xxxx. By pressing ok you will link to google.com",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Ok",
        cancelButtonText: "Cancel",
        closeOnConfirm: false,
        closeOnCancel: false,
      },
      function(isConfirm){
        if (isConfirm) {
          window.location.href = "google.com"
        }
      }
    );
      
    }
    </script>

在gem文件中

gem 'rails-assets-sweetalert2', source: 'https://rails-assets.org'
gem 'sweet-alert2-rails'
gem 'sweet-alert-confirm'

在application.js

//= require sweetalert2
//= require jquery
//= require jquery_ujs
//= require sweet-alert2-rails
//= require cocoon 
//= require sweet-alert-confirm  
//= require_tree .

在application.scss

 *= require_self
 *= require sweetalert2
 *= require_tree .
 */

你必须使用.then(),然后在其中传递重定向程序:

示例:

function sweetalertclick() {

swal({
    title: 'Request a DDS',
    text: "Please log in to DDS website to request a pick up, my code is: xxxx. By pressing ok you will link to google.com",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "Ok",
  }).then((result) => {
  console.log(result)
    if (result) {
      window.location.href = "google.com";
    }
  });
  
}