Javascript 具有重定向功能的javascript windows警报

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5443568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 17:12:57  来源:igfitidea点击:

javascript windows alert with redirect function

phpjavascripthtml

提问by zerey

.guys I have the following code:

.伙计们我有以下代码:

echo ("<SCRIPT LANGUAGE='JavaScript'>
        window.alert('Succesfully Updated')
        </SCRIPT>");

what i want to do is that when i click ok on the windows.alert the page will be redirected to a my edit.php.

我想要做的是,当我在 windows.alert 上单击确定时,页面将被重定向到我的 edit.php。

or how is it possible to create a javascript which will execute an insert query.

或者如何创建一个将执行插入查询的 javascript。

回答by Pickels

Alert will block the program flow so you can just write the following.

Alert 将阻塞程序流,因此您只需编写以下内容即可。

echo ("<script LANGUAGE='JavaScript'>
    window.alert('Succesfully Updated');
    window.location.href='http://someplace.com';
    </script>");

回答by Imi Borbas

If you would like to redirect the user after the alert, do this:

如果您想在警报后重定向用户,请执行以下操作:

echo ("<script LANGUAGE='JavaScript'>
          window.alert('Succesfully Updated');
          window.location.href='<URL to redirect to>';
       </script>");

回答by Karl Nicoll

You could do this:

你可以这样做:

echo "<script>alert('Successfully Updated'); window.location = './edit.php';</script>";

回答by jpakes

Use this if you also want to consider non-javascript users:

如果您还想考虑非 JavaScript 用户,请使用此选项:

echo ("<SCRIPT LANGUAGE='JavaScript'>
           window.alert('Succesfully Updated')
           window.location.href='http://someplace.com';
       </SCRIPT>
       <NOSCRIPT>
           <a href='http://someplace.com'>Successfully Updated. Click here if you are not redirected.</a>
       </NOSCRIPT>");