繁体   English   中英

警报框弹出-单击“确定”进行重定向

[英]Alert box pops up - redirect on click “OK”

我想在警报框中单击“确定”时重定向用户。 任何提示将不胜感激

if( $num_rows == 0 ) {
    // No results returned
    echo "No results!";
} else {
    $message = "Information already sent";
echo "<script type='text/javascript'>alert('$message');</script>";
}
echo "<script type='text/javascript'>
   alert('$message');
   document.location.href='your url';
</script>";

您可以使用window.location.href重定向到javascript中的任何页面,以便在使用后将其重定向到test.php,在Alertbox中单击OK:

if( $num_rows == 0 ) {
    // No results returned
    echo "No results!";
} else {
    $message = "Information already sent";
    echo "<script type='text/javascript'>alert('$message');window.location.href='test.php';</script>";
}
echo "<script>alert('Update Not Successfully');document.location='pagename.php'</script>";

使用window.location.replace(url)优于window.location.href = url ,因为它不允许用户使用浏览器中的“历史上的上一页”按钮返回此页面。

它执行真正的重定向,而不仅仅是转到下一个URL:

if( $num_rows == 0 ) {
    // No results returned
    echo "No results!";
} else {
    $message = "Information already sent";
    echo "<script type='text/javascript'>alert('$message'); window.location.replace('test.php'); </script>";
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM