我正在客户端浏览器上显示一个消息框。它工作正常,但当弹出此警报消息框时,我在后面看到一个空白页。但我希望用户始终看到他的浏览页面并弹出此消息框。这是我的代码。` if($_POST['提交']=="保存") {
$language=$_POST['pbx_lan'];
if($language!="")
{
$query="update `account_detail` set `prompt_language`= '$language' WHERE `org_id`='".$_SESSION['account_id']."'";
$result = $mysqli->query($query) or die($mysqli->error);
$_SESSION['check_update'] = "1";
// setcookie("msg","Language Successfully Updated",time()+5,"/");
echo '<script>
confirm("You have selected '.$language.'");
window.location = "'.SITE_URL.'index.php?view=pbx_prompts."
</script>';
// header("location:".SITE_URL."index.php?view=view_service");
}
else
{
setcookie("err","No Language Selected.Please Select Language",time()+5,"/");
header("location:".SITE_URL."index.php?view=view_service");
}
}`
最佳答案
当调用 confirm()
时,页面将停止加载。当您在页面末尾添加 confirm()
时,页面会在显示 confirm()
之前加载
<body>
TEST123
<script>
confirm('test');
</script>
</body>
而不是
<body>
<script>
confirm('test');
</script>
TEST123
</body>
对于您的代码,这意味着
echo '<script>
confirm("You have selected '.$language.'");
window.location = "'.SITE_URL.'index.php?view=pbx_prompts."
</script>';
必须移至 body
标记的底部
还要复制所需的 if
语句,以便仅在需要时执行代码。
body
标记底部的完整代码应如下所示:
if (!empty($language) && $_POST['submit'] == "Save") {
echo '<script>
confirm("You have selected '.$language.'");
window.location = "'.SITE_URL.'index.php?view=pbx_prompts."
</script>';
}
关于javascript - 警报消息框后面显示空白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32688900/