简体   繁体   English

对不更改URL哈希值的页面加载启用浏览器的后向/前向导航

[英]Enabling browser back/front navigation for page loads that don't change URL hash

I have an Ajax site where I have browser navigation hooked up to ajax page loads in cases where navigation results in a change to the URL hash. 我有一个Ajax站点,如果导航导致URL哈希值发生变化,我会将浏览器导航链接到ajax页面加载。

I was wondering what the best way to get navigation history is for ajax loads that don't result in a change to the hash. 我想知道获取导航历史记录的最佳方法是对不导致哈希值更改的ajax加载。

So, say I have 'Level 1' links which, on clicking, result in a URL hash change. 因此,假设我有“第1级”链接,该链接在单击后会导致URL哈希更改。 Something like the jquery history plugin picks that up and invoked my handler, and front/back navigation works fine for these 'Level 1' links. 诸如jquery history插件之类的东西可以接管并调用我的处理程序,并且前向/后向导航对于这些“级别1”链接均适用。

But I have a set of 'Level 2' links that fetch data using the 'click' handler (which internally do some Ajax fetches) instead of going the URL hash + history plugin route. 但是我有一组“ 2级”链接,这些链接使用“单击”处理程序(内部执行一些Ajax提取)来获取数据,而不是使用URL哈希+历史记录插件路由。 These currently don't result in a change to the URL/hash. 这些目前不会导致更改URL /哈希值。 I want these 'Level 2' links to be browser navigation enabled. 我希望这些“第2级”链接启用浏览器导航。

It seems like for this to work smoothly, I must change the URL so my guess is any solution here involves decorating the hash some more. 为了使此操作顺利进行,我必须更改URL,所以我的猜测是这里的任何解决方案都涉及装饰哈希。 One solution that might work but I'd never consider seriously is to encode the JS function name I wish to execute and the params into the URL hash somehow, and then have my history load handler invoke that function. 一种可能有效但我从未认真考虑过的解决方案是,将希望执行的JS函数名称编码,并将参数以某种方式编码到URL哈希中,然后让我的历史记录加载处理程序调用该函数。 Blech! 布莱什!

Anyone have clever ideas about how I can do this? 有人对我该如何做有聪明的主意吗?

嗯...也许您正在寻找jQuery BBQ插件

One thing I did for a project was use hash values like this: 我为一个项目所做的一件事是使用像这样的哈希值:

IDProduct-8185--tab-tech--g-8184

Meaning there were 3 parameters: IDProduct = 8185, tab = "tech", and g = 8184. Then, I'd split by "--" and loop over the resulting array. 这意味着有3个参数:IDProduct = 8185,tab =“ tech”,g =8184。然后,我用“-” split并遍历结果数组。 Probably not the most elegant solution, and works for very simple parameter values only. 可能不是最优雅的解决方案,并且仅适用于非常简单的参数值。 Better have a look at the BBQ plugin that Sean is suggesting first. 最好看看Sean首先建议的BBQ插件。

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

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