简体   繁体   English

调用PHP / Javascript中的浏览器后退按钮

[英]Invoke the browser back button in PHP/Javascript

I have a form which sends the user to a different form incase they don't complete it to go back to the form and complete anything that was missed. 我有一个表单,可以将用户发送到其他表单,以防万一他们没有完成表单以返回表单并完成所有遗漏的事情。 Now unless the user presses the browser back button the page is loaded fresh which mean any data gets lost. 现在,除非用户按下浏览器的“后退”按钮,否则页面将重新加载,这意味着所有数据都将丢失。

Pretty much when they come back to the previous page, anything they already filled in should stay intact. 当他们回到上一页时,几乎已经填写的所有内容都应保持不变。

I have the following two pages: 我有以下两页:

Page 1: 第1页:

<?PHP

echo "<a href='page2.php'>NEXT</a>";
echo "<input type=text size=25 name=txt />";
?>

Page 2: 第2页:

<?php
$refer = $_SERVER['HTTP_REFERER'];
$lastlink = "<a href='$refer'>BACK</a>";

echo $lastlink;
?>

On page two if i click BACK to come back to page 1, anything entered in page 1 will be lost which I do not want. 在第二页上,如果我单击“返回”返回到第一页,则在第一页中输入的所有内容都会丢失,这是我不希望的。 How do I work around it without using Javascript? 不使用Java脚本怎么办? with Javascript? 用JavaScript? I know in javascript I can use 我知道我可以使用javascript

<a href="javascript:history.go(-1);">BACK</a>

But is there another way? 但是还有另一种方法吗?

Take a look at html5 history api . 看看html5 history api History api + ajax is great combination 历史API + Ajax完美结合

您还可以使用会话在提交时存储$_POST ,并检查是否在第一个表单的页面加载中设置了该值。

I am usually satisfied with: 我通常对以下内容感到满意:

history.back(-1);

Sending back to a previous page using Server-Side logic, is not a good approach to do, so I will disencourage it. 使用服务器端逻辑发送回上一页不是一个好方法,因此,我不鼓励这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM