如何返回上一页并在 php 或 javascript 中刷新它?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28896689/
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
How to return to previous page and refresh it in php or javascript?
提问by mirzak
How can user return to the page he came from, and refresh its content, using PHP or javascript.
用户如何使用 PHP 或 javascript 返回到他来自的页面并刷新其内容。
I've used this to get back to the page :
我用它回到页面:
header("Location: javascript:history.back(-1)");
but it needs to be refreshed after that.
但之后需要刷新。
回答by RiggsFolly
You cannot execute javascript in a PHP script.
您不能在 PHP 脚本中执行 javascript。
In PHP you can make use of the $_SERVER["HTTP_REFERER"]
variable in the header()
statement like so
在 PHP 中,您可以像这样使用语句中的$_SERVER["HTTP_REFERER"]
变量header()
header('Location: ' . $_SERVER["HTTP_REFERER"] );
exit;
Its always a good idea to follow a header()
statement with an exit
or code execution will continue through the rest of the script as normal.
遵循header()
带有exit
或 代码执行的语句始终是一个好主意,它会像往常一样继续执行脚本的其余部分。
回答by Joe Fitter
If you just want to use javascript you can use window.history.back()
如果您只想使用 javascript,您可以使用 window.history.back()
function goBack() {
window.history.back();
}