在Javascript中,最好是JQuery,当用户点击“返回”时,如何向URL添加内容?浏览器中的按钮? [英] In Javascript, preferably JQuery, how do I add something to the URL when the user clicks "back" button in the browser?

查看:60
本文介绍了在Javascript中,最好是JQuery,当用户点击“返回”时,如何向URL添加内容?浏览器中的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当浏览器点击返回按钮时,我想在网址上附加& page = 3。
如何绑定它,然后执行此操作?

When the browser clicks "back" button, I want to append "&page=3" to the URL. How do I bind it, and then do this?

编辑:我希望这很简单。

I want this very simple.

BIND the event{
window.location(that-url + "&page=3")
}

可以这样做吗?

推荐答案

alt text http:// a3 .twimg.com / profile_images / 267631291 / clippy_normal.png 听起来你正在尝试创建一个历史插件。

alt text http://a3.twimg.com/profile_images/267631291/clippy_normal.png It sounds like you're trying to create a history plugin.

你是否尝试过使用 mikage历史插件

我不建议在离开当前页面时(这是后退按钮的操作)更改URL,因为您会立即删除前进历史记录(从而中断前进按钮)。当尝试使用分页和javascript / ajax处理后退按钮时,更典型的是使用浏览器哈希来传递参数。使用前进和后退按钮时,不会清除JavaScript命名空间,并根据使用的导航更新哈希值。这些历史插件有两种方法可以检测何时使用导航(因为doc load事件不会触发)。

I wouldn't recommend changing the URL when they navigate away from the current page (which is what the back button does), because you immediately erase the forward history (thus breaking the forward button). When trying to handle the back button with pagination and javascript/ajax it is more typical to use the browser hash to pass parameters. The JavaScript namespace doesn't get cleared when the forward and backward buttons are used and the hash is updated according to what navigation was used. These history plugins have a couple of methods to detect when navigation is used (as the doc load event doesn't fire).

所以要注意,编写历史插件不是'因为浏览器无法一致地处理位置对象(窗口对象的一部分)的哈希属性的方式,所以直截了当。你肯定想看看别人做了什么。

So beware, writing a history plugin isn't straightforward because of the way browsers fail to consistently handle hash property of the location object (part of the window object). You will definitely want to look at what others have done.

这篇关于在Javascript中,最好是JQuery,当用户点击“返回”时,如何向URL添加内容?浏览器中的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆