当用户点击甜蜜警报的确定按钮时重定向到网页

如何解决当用户点击甜蜜警报的确定按钮时重定向到网页

我正在使用甜蜜警报(https://sweetalert2.github.io/)以这种方式在注册后弹出成功警报:

    <script>
    swal('Registration was successful','Welcome to bottles beach','success');
    console.log("Form is correct and submitted");
    </script>

但是我不知道为什么如果我使用这种其他方式甜蜜警报不起作用:

  <script>
  Swal.fire({
  icon: 'error',title: 'Oops...',text: 'Something went wrong!',footer: '<a href>Why do I have this issue?</a>'
})
 </script>

我希望如果用户点击确定,他将被重定向到另一个网页,但我不知道该怎么做,但我在网上找到只使用一旦用户单击“确定”按钮,将用户重定向到网页的第二种形式; 有人知道我该怎么做吗?

我使用这个库版本:https://unpkg.com/sweetalert/dist/sweetalert.min.js

2个问题需要解决: - 不工作(没有出现) Swal.fire 但只有 swal 工作(...) - 当用户在甜蜜警报中单击确定时,我如何重定向用户?

完整代码:

    <!DOCTYPE html>
<html>
<head>
<title>Bottles Beach - Send your bottles</title> <!--Bottles Island-->
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">

<!--sweet alert lib-->
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>




<style>

body,html {
  height: 100%;
  margin: 0;
  font-family: Arial,Helvetica,sans-serif;
  background-color: #7d5c3c;
}

.topnav {
  overflow: hidden;
  background-image:linear-gradient(180deg,#288bd7,#64ABE3,#64ABE3); background-size: 100%;
  
}
* {
  box-sizing: border-box;
}

.topnav a {
  float: left;
  display: block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
}

.topnav a:hover {
  background-image:linear-gradient(100deg,#64ABE3); background-size: 100%;
  transition: all 1 ease;
  color: white;
}

.topnav a.active {
  background-color: #62b1d0;
  color: #f2f2f2;
}

.topnav .icon {
  display: none;
}

@media screen and (max-width: 600px) {
  .topnav a:not(:first-child) {display: none;}
  .topnav a.icon {
    float: right;
    display: block;
  }
}

@media screen and (max-width: 600px) {
  .topnav.responsive {position: relative;}
  .topnav.responsive .icon {
    position: absolute;
    right: 0;
    top: 0;
  }
  .topnav.responsive a {
    float: none;
    display: block;
    text-align: left;
  }
}
.txt {
  background-color: rgb(0,0); /* Fallback color */
  background-color: rgba(0,0.4); /* Black w/opacity/see-through */
  color: white;
  font-weight: bold;
  border: 3px solid #f1f1f1;
  position: absolute;
  top: 53%;
  left: 50%;
  transform: translate(-50%,-50%);
  z-index: 2;
  width: 80%;
  padding: 20px;
  text-align: center;
}

.txt:hover
{
    background-color: rgb(0,0.5); /* Black w/opacity/see-through */
  color: rgba(240,238,242);
  font-weight: bold;
  border: 3px solid #f1f1f1;
  position: absolute;
  top: 53%;
  left: 50%;
  transform: translate(-50%,-50%);
  z-index: 2;
  width: 80%;
  padding: 20px;
  text-align: center;
}

/*scroll bar*/
::-webkit-scrollbar {
  width: 10px;
}

/* Track */
::-webkit-scrollbar-track {
  background: #f1f1f1; 
}
 
/* Handle */
::-webkit-scrollbar-thumb {
  background: #888; 
}

/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
  background: #555; 
}

.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 1; /* Sit on top */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgb(0,0.4); /* Black w/ opacity */
}

/* Modal Content/Box */
.modal-content {
  background-color: #fefefe;
  margin: 14% auto; /* 15% from the top and centered */
  padding: 20px;
  border: 1px solid #888;
  width: 80%; /* Could be more or less,depending on screen size */
}

/* The Close Button */
.close {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
}

.close:hover,.close:focus {
  color: black;
  text-decoration: none;
  cursor: pointer;
}
.container {
  margin: 10px auto;
  height: 100%;
  display: flex;
  justify-content: center;
  background-color: #966e47;
}



.board {
  margin: 10px;
  height: calc(100% - auto);;
  width: calc(100% - 20px);
  background-color: #b08153;
  font-size: 2.5em;
  font-weight: bold;
  color: white;
  text-align: center;
}


.input{

    border-radius: 3px;
    border: none;
    width: 100%;
    height: 32px;
    background-color: #333333;

}

.lbl{
    color: white;
}



.btnstyle{

    width: 100%;
    border: none;
    border-radius: 3px;
    background-color: #333333;
    color: white;
    text-color: black;
    height: 34px;
    margin-top: 10%;

}

.grandParentContaniner{
    display:table; height:70%; margin: 0 auto;
}

.parentContainer{
      display:table-cell; vertical-align:middle;
      text-align: center;
      width: 120%;
      transition: all 1.9s ease;  

}
.parentContainer:hover{
      width: 70%;  
      transition: all 0.9s ease;
}
.form_login{
  transition: all 1.5s ease;
  width: 100%;
  padding: 25px;
  border-radius: 10px;
  background-image:linear-gradient(150deg,#BBDBF7,#BBDBF7);
  background-size: 100%;
}

</style>
</head>
<body>



<div class="topnav" id="myTopnav"> 
  <a href="index.php">Send a Bottle</a>
  <a href="bottles.php" class="active">Bottles</a>
  <a href="cht.php" >Chat</a>
  <a href="about.php">About</a>
  <a href="donate.php">Donate</a>
  <a href="javascript:void(0);" class="icon" onclick="myFunction()">
  <i class="fa fa-bars"></i>
  </a>
</div>
<br>
  <div class="grandParentContaniner">
    <div class="parentContainer">
      <div class="form_login">
        <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> 
          <h1 style="margin-bottom: 10%; color: #333333">Sign-in</h1>   
          <hr width="100%" style="color: black"> <br>
          <input type="input" name="username" class="input" placeholder="insert your username"><br><br>
          <input type="input" name="e-mail" class="input" placeholder="insert your e-mail"><br><br>
          <input type="input" name="password" class="input" placeholder="retype your password"><br><br>
          <input type="input" name="rtpassword" class="input" placeholder="insert your password"><br><br><br>
          <input type="submit" class="btnstyle" value="Sign in">
        </form>
        <a href="login.php"><button class="btnstyle">Log-in</button></a>
      </div>
    </div>
  </div>
 

  
  <?php

  //Connect To Database
  
  $username="";
  $password="";
  $dbname="";
  $name ="";
  $hour =date('H:i');
  $insert = "";
  $cont = 0;
  $dt = date("Y-m-d");

$conn = new mysqli($hostname,$username,$password,$dbname); 
  if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

  /*
  
  */
  
 

  if($_SERVER["REQUEST_METHOD"] == "POST"){

     
      $username = $_POST["username"];
      $email = $_POST["e-mail"];
      $password = $_POST["password"];
      $rtpassword = $_POST["rtpassword"];
      $nook = false;
      $errsameuser = false;

      $queryy = "SELECT username FROM users";
      $result = $conn->query($queryy);
      
      if ($result->num_rows > 0) 
      {
        //output data of each row
      while($row = $result->fetch_assoc()) 
       {
        if( $row["username"] == $username){  //username already exist
            $errsameuser = true;
    }
  }
 }

      

      if($password == $rtpassword){ //pssw e conferma pssw enno uguali
        
        ?>
        <script>
        console.log("password 1 and 2 match");
        </script>
        <?

        if(strlen($password) < 8)
          $nook = true;
        
        if(!preg_match("#[a-z]+#",$password) ) //pssw must cointain at least  lower word
         $nook = true;
         
         if(!preg_match("#[A-Z]+#",$password) ) //pssw must cointain at least upper word
         $nook = true;
         
        if ( !preg_match("/[\'^£$%&*()}{@#~?><>,|=_+!-]/",$password) )  //pssw must cointain at least special character
         $nook = true;
         
        if ( !preg_match("#[0-9]+#",$password) )  //pssw must cointain at least number
        $nook = true;
        


        if($nook){
            ?>
        <script>
        console.log("but password not ok")
        </script>
            <?
        }

        if($errsameuser){
          ?>
        <script>
        swal('This username already exists','Please choose a new username','error');
        </script>
        <?
        }

       

        else{
            $query = "INSERT INTO users (username,email,password) VALUES ('$username','$email','$password')";
            $result = $conn->query($query);
     ?>
        
        <script>
        Swal.fire({
  title: 'Welcome to bottles beach',text: "You successfully submitted the form",icon: 'success',showCancelButton: false,confirmButtonColor: '#3085d6',confirmButtonText: 'Great,show me the site!'
}).then((result) => {
  if (result.isConfirmed) {
    location="somewhereelse.html"
  }
})
        console.log("Form is correct and submitted");
        </script>
            <?
    



        }

      }
      
  }
  
$conn->close();

?>
  <!-- Modal content -->
 

<script>

function myFunction() {
  var x = document.getElementById("myTopnav");
  if (x.className === "topnav") {
    x.className += " responsive";
  } else {
    x.className = "topnav";
  }
}
var modal = document.getElementById("myModal");


// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

 function openpopup() {
   modal.style.display = "block";
  }



// When the user clicks on the button,open the modal


// When the user clicks on <span> (x),close the modal
span.onclick = function() {
  modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal,close it
window.onclick = function(event) {
  if (event.target == modal) {
    modal.style.display = "none";
  }
}

</script>

</body>
</html>

解决方法

Manual

Swal.fire({
  title: 'Welcome to bottles beach',text: "You successfully submitted the form",icon: 'success',showCancelButton: false,confirmButtonColor: '#3085d6',confirmButtonText: 'Great,show me the site!'
}).then((result) => {
  if (result.isConfirmed) {
    location = "somewhereelse.html"
  }
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10.15.6/dist/sweetalert2.all.min.js"></script>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res