按下警告按钮后重定向到页面/ URL [英] Redirect to a page/URL after alert button is pressed

查看:117
本文介绍了按下警告按钮后重定向到页面/ URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经提到了这两个问题在Javascript函数下调用php页面按下警告按钮后转到URL 。我想在调用警告框后重定向到我的index.php。我的警报框在我的其他声明中。下面是我的代码:

i have referred to this two questions call php page under Javascript function and Go to URL after OK button in alert is pressed. i want to redirect to my index.php after an alert box is called. my alert box is in my else statement. below is my code:

processor.php

processor.php

    if (!empty($name) && !empty($email) && !empty($office_id) && !empty($title) && !empty($var_title) && !empty($var_story) && !empty($var_task) && !empty($var_power) && !empty($var_solve) && !empty($var_result)) {

    (some imagecreatefromjpeg code here)

    else{
        echo '<script type="text/javascript">'; 
        echo 'alert("review your answer")'; 
        echo 'window.location= "index.php"';
        echo '</script>';   
    }

它没有显示任何内容(没有警告框而没有重定向)。当我删除这部分 echo'window.location =index.php'; 它显示警报。但仍然没有重定向到index.php。希望你能帮助我。请不要标记重复,因为我已将帖子作为参考。非常感谢你的帮助。

it's not displ ying anything(no alert box and not redirecting). when i delet this part echo 'window.location= "index.php"'; it's showing the alert. but still not redirecting to index.php. hope you can help me with this. please dont mark as duplicate as i have made tose posts as reference. thank you so much for your help.

推荐答案

你的javascript行后遗漏了分号。此外, window.location 应该有 .href .replace 等重定向 - 有关详细信息,请参阅此帖子。

You're missing semi-colons after your javascript lines. Also, window.location should have .href or .replace etc to redirect - See this post for more information.

echo '<script type="text/javascript">'; 
echo 'alert("review your answer");'; 
echo 'window.location.href = "index.php";';
echo '</script>';

为清楚起见,请尝试为此保留PHP标签:

For clarity, try leaving PHP tags for this:

?>
<script type="text/javascript">
alert("review your answer");
window.location.href = "index.php";
</script>
<?php

注意:单独行上的半冒号是可选的,但鼓励 - 但是在下面的评论中,PHP不会在第一个示例中断行,但在第二个示例中,第一个示例中需要

NOTE: semi colons on seperate lines are optional, but encouraged - however as in the comments below, PHP won't break lines in the first example here but will in the second, so semi-colons are required in the first example.

这篇关于按下警告按钮后重定向到页面/ URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆