【问题标题】:Change browser address bar URL with jQuery & ajax without reloading page [duplicate]使用 jQuery 和 ajax 更改浏览器地址栏 URL 而无需重新加载页面 [重复]
【发布时间】:2012-08-23 17:59:30
【问题描述】:

使用 jQuery 更改浏览器地址栏 URL 而无需重新加载 例如,

www.mywebsite/list.php?page=1

<a href="?page=<?php $row[id] ?>" > this link </a>

点击更改地址栏?id=123等...

【问题讨论】:

标签: php jquery ajax


【解决方案1】:

你不能。 例如,如果您尝试这样做:

document.location.search= "?i=123"

它将重新加载页面。 您可以做的是更改哈希

document.location.hash= "#123"

document.location.hash= "#i=123

然后使用 split 编写一个简单的解析器来获取您需要的数据。 类似的question你应该看看。

【讨论】:

  • 请注意,#(哈希)参数不能在服务器端读取,例如? (查询)参数 - 在 urls 中 # 的初始用法是“go-to anchor/id”功能
【解决方案2】:

jQuery: pjax 插件可以帮助你。

【讨论】:

    【解决方案3】:

    根本不可能在不重新加载的情况下更改浏览器的 url 甚至查询字符串,只有在不刷新的情况下可以更改的部分是 url 的 #hash 部分,直到 html4

    但在 html 5 中,可以通过新的 HISTORY API 进行某种 url 更改,试试看

    http://html5demos.com/history

    【讨论】:

      猜你喜欢
      • 2012-06-12
      • 1970-01-01
      • 2012-03-18
      • 2013-10-12
      • 2013-04-25
      • 2020-06-20
      • 1970-01-01
      • 2016-06-08
      • 2016-01-12
      相关资源
      最近更新 更多