即使提交基于PRG的表单,Chrome也会跟踪2个历史记录条目

时间:2013-03-26 17:17:53

标签: php forms node.js google-chrome browser-history

Chrome在提交实施“Post + Same Page Redirect + Get”方法的表单时,会跟踪两个历史记录条目 - 而不是一个 -

证明这种奇怪行为的步骤。

1 - 我浏览到表单页面Naked form page:demo.html。 裸体表格页面: Naked form page (demo.html)

2 - 我填写表格。 填写表格:

Filled form (demo.html)

3 - 我提交表格。 Submited -thus empty - form(在demo.html中,从我的基于PRG的重定向到同一页面.php重定向):

enter image description here

4 - 我点击浏览器的“后退”按钮一次。

Chrome跳回填充表单(步骤)

enter image description here

5 - 我需要再次点击浏览器的“后退”按钮,才能访问我在浏览该页面之前浏览的页面(比如我的浏览器的“google”默认页面): enter image description here

Chrome(版本25.0.1364.172)和Safari(6.0.2)

会发生这种情况

我期待什么

我希望只有一个浏览器的“后退”点击才能到达表单前的页面。 这实际上是Firefox(19.0.2)Opera(12.11)和IE(从版本6到最新版本10)的行为。

我的源代码

demo.html

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
    <form action="redirect-to-same-page.php" method="post">
    Type something and submit: <input type="text" name="something" /> <!-- optional: autocomplete="off" -->
    <input type="submit" value="submit" />
    </form>

</body>
</html>

重定向到相同-page.php文件

<?php
header('Location: demo.html', true, 302); // not any of true/false 302/303 combinations are working
// not working either: header("Refresh: 0; demo.html");
exit;
?>

Chrome的网络检查员揭示了什么......

1提交前: enter image description here

2提交后: enter image description here

我的问题

我读过类似的问题和可能的答案,但没有一个能解决我的问题。

此行为是Chrome / Safari问题还是功能*? (*如果提交失败,则会保留填写表格的完整备份)

是否有针对node.js或php的正确或更具防御性的代码以避免此行为?

感谢您的帮助

0 个答案:

没有答案