2

I'm looking for a good pushstate jquery plugin to work with ajax-json (and php's mod_rewrite when js is turned off) and found jQuery Address. I like it a lot since it's well documented and easy to work with. (I never really figured out history.js) I noticed however that the great internet explorer (9) puts hashes there in the href field. It's doing it in the example as well: http://www.asual.com/jquery/address/samples/state/contact I've tested other browsers but you can only see this with the great internet explorer. Any way around this?

4

1 回答 1

6

Internet Explorer 9不支持历史 API。相反,使用这些 api 的应用程序必须回退到onhashchange功能,它利用位置的片段在功能较弱的浏览器中复制类似的功能。

您所看到的是预期的;Internet Explorer 10+ 支持这个更新的功能,因此不需要添加/#到 url 来记录和保存状态历史。Internet Explorer 9 不支持 History API,因此必须做出规定。

您提到了 history.js,它扩展了对history.pushState非 HTML5 浏览器等方法的支持。在这个项目的GitHub 页面上,您可以看到一些示例,说明 url 在新浏览器中的显示方式以及它们在旧浏览器中的显示方式。正如预期的那样,您现在所体验的模式也是在那里产生的。

尽管在 Internet Explorer 9 中查看时,您的 url 中有一个片段,但请注意,这并不反映您服务器上请求的路径。请注意在浏览器中输入的请求地址,以及“网络”选项卡中对服务器的实际请求:

在此处输入图像描述

解决 404

您在 IE9 中获得 404 的原因是因为在不支持 HTML5 History API 的浏览器中,jQuery.address 将重新导航到您在设置中提供的任何状态。因此,当您输入 url 时,初始请求会传递给您的服务器。此地址由 mod_rewrite 处理,您RewriteRules确定要加载的初始内容。

当您的初始内容被加载并设置 jQuery.address 时,甚至会在您的设置路径中发生新的导航。在你的情况下,这是/posters. 不幸的,您没有任何RewriteRules地方可以向./posters

这可以通过再次访问 F12 开发人员工具的网络选项卡并捕获数据来确认。打开该选项卡后,按“开始捕获”,然后输入购物车中产品的完整路径。您会注意到对该完整路径的初始请求,然后加载了几个依赖项。不久之后,您将看到另一个导航事件发生在您提供的任何路径上$.address.state

于 2012-12-12T20:48:04.513 回答