I was wondering if there was any way through php or javascript I could tell the browser to go back to the page it came from, or even better not load the page at all (the later being probably impossible).
我想知道是否有任何方式通过PHP或javascript我可以告诉浏览器回到它来自的页面,或甚至更好不加载页面(后来可能是不可能的)。
The reason for this is that I have written a small php script that will take parameters from the url and post a tweet for me discreetly while I am at work.
这样做的原因是我写了一个小的PHP脚本,它将从网址中获取参数,并在我工作时谨慎地发布推文。
ex.
tweet.php?user=myname&pass=mypass&message=My message goes here
Though it works, I get stuck with a white page. It would be nice if I could have the browser go back to the page it was just on, so the pause between work would be minimal.
虽然它有效,但我还是被白页困住了。如果我可以让浏览器返回它刚刚打开的页面,那将是很好的,因此工作之间的暂停将是最小的。
Thank you for the help!
感谢您的帮助!
7 个解决方案
#1
The JavaScript function for this is window.back()
. Have your PHP script produce something like the following to have browsers automatically "bounced back" to the submitting page:
这个JavaScript函数是window.back()。让您的PHP脚本产生如下内容,让浏览器自动“退回”到提交页面:
<html>
<head>
<title>Success</title>
</head>
<body onload="window.back()">
<h1>Success</h1>
</body>
</html>
Non-JS browsers will see a "success" message, JS browsers will get bounced back.
非JS浏览器将看到“成功”消息,JS浏览器将被反弹。
#2
javascript: history.go(-1);
#3
You could do the following in PHP to redirect back to the previous page:
您可以在PHP中执行以下操作以重定向回上一页:
<?php
$ref = $_SERVER['HTTP_REFERER'];
header('refresh: 10; url='.$ref);
?>
#4
Depending on the browser, either an HTTP response code of 204 or 205 might cause it to not leave the current page.
根据浏览器的不同,HTTP响应代码204或205可能会导致它不离开当前页面。
#5
If use use a PHP HEADER, you can redirect to another point on the site. Minimal Pause work (as long as the process isn't very long).
如果使用PHP HEADER,您可以重定向到站点上的另一个点。最小暂停工作(只要过程不是很长)。
#6
#7
Sending people back to the page without any success message would be very confusing. I would make the call with AJAX and provide some feedback to the user that the action was performed successfully, very much like the voting system here on SO works.
将人们发送回页面而没有任何成功消息将会非常混乱。我会使用AJAX进行调用,并向用户提供一些反馈,表明该操作已成功执行,非常类似于此处的SO投票系统。
#1
The JavaScript function for this is window.back()
. Have your PHP script produce something like the following to have browsers automatically "bounced back" to the submitting page:
这个JavaScript函数是window.back()。让您的PHP脚本产生如下内容,让浏览器自动“退回”到提交页面:
<html>
<head>
<title>Success</title>
</head>
<body onload="window.back()">
<h1>Success</h1>
</body>
</html>
Non-JS browsers will see a "success" message, JS browsers will get bounced back.
非JS浏览器将看到“成功”消息,JS浏览器将被反弹。
#2
javascript: history.go(-1);
#3
You could do the following in PHP to redirect back to the previous page:
您可以在PHP中执行以下操作以重定向回上一页:
<?php
$ref = $_SERVER['HTTP_REFERER'];
header('refresh: 10; url='.$ref);
?>
#4
Depending on the browser, either an HTTP response code of 204 or 205 might cause it to not leave the current page.
根据浏览器的不同,HTTP响应代码204或205可能会导致它不离开当前页面。
#5
If use use a PHP HEADER, you can redirect to another point on the site. Minimal Pause work (as long as the process isn't very long).
如果使用PHP HEADER,您可以重定向到站点上的另一个点。最小暂停工作(只要过程不是很长)。
#6
In tweet.php, use the header function to redirect back to the referer
在tweet.php中,使用header函数重定向回referer
#7
Sending people back to the page without any success message would be very confusing. I would make the call with AJAX and provide some feedback to the user that the action was performed successfully, very much like the voting system here on SO works.
将人们发送回页面而没有任何成功消息将会非常混乱。我会使用AJAX进行调用,并向用户提供一些反馈,表明该操作已成功执行,非常类似于此处的SO投票系统。