改变 JavaScript 历史

发布于 2024-10-04 04:24:10 字数 303 浏览 1 评论 0原文

当我加载 php 页面时,我会附加一些数据。例如 MyPage.php?value=something。 正如预期的那样,当我使用后退按钮来回移动时,它总是会加载附加的相同数据。我不想要这样。我希望在页面加载后,我应该能够更改历史记录以仅存储 MyPage.php,而不存储附加数据。所以现在当我使用后退按钮时,它只会加载 MyPage.php。我怎样才能做到这一点 - javascript,jquery,php,任何东西???

如果有一种方法可以在不接触历史对象的情况下做到这一点,那也很好。我只是假设这需要一些历史调整。如果需要在客户端或服务器端进行调整,我也可以接受。

When I load my php page I append some data. For instance MyPage.php?value=something.
As expected, when I go back and forth using the back button, it always loads with that same data appended. I don't want that. I want that after the page loads, I should be able to change the history to store only MyPage.php WITHOUT the appended data.So now when I would use the back button it would load MyPage.php only. How can I do this - javascript, jquery, php , anything???

If there is a way to do that without touching the history object, thats also fine. I'm just assumng it'll take some history tweaking. I'm also OK if it takes tweaking on the client or server side.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

谁把谁当真 2024-10-11 04:24:10

据我所知,这样调整历史是不可能的,也不是处理这个问题的好方法。

您可以使用 cookie 来确定页面何时加载两次以上,或者将数据存储在会话变量中,并在处理完成后将其删除。

As far as I know, it is not possible to tweak the history like that, nor is it a good way to deal with this.

You could use a cookie to determine when a page gets loaded more than twice, or store the data in a session variable instead, and delete it once your processing is done.

九厘米的零° 2024-10-11 04:24:10

我假设数据是使用 GET 方法附加的。使用 POST 不会在 MyPage.php 之后附加文本,但仍然可以将数据传递到页面。

I assume the data is appended by using GET method. Using POST will not append text after MyPage.php but still can pass data to the page.

风吹过旳痕迹 2024-10-11 04:24:10

历史就是历史。改变它有点麻烦(如果你这样做的话,你可能会遇到其他问题)。

最好是根本没有查询字符串,并使用 js 或服务器端逻辑来确定操作,或者使用 js 或服务器端逻辑来忽略第二个请求。

The history is the history. It's a bit of a hack to go changing that (and you will probably have other issues down the road if you do).

It is better to either have NO querystring at all, and use js or server-side logic to determine the action, or to have js or server-side logic to ignore the second request.

硬不硬你别怂 2024-10-11 04:24:10

如果您愿意调整历史记录,那么您可能可以查看一下。

history.replaceState({}, document.title, "MyPage.php");

这会将当前的 window.location 重写为“MyPage.php”,而无需刷新页面。

If you are fine with tweaking the history then you can probably look in to this.

history.replaceState({}, document.title, "MyPage.php");

This will rewrite the current window.location to "MyPage.php" without page refresh.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文