使用jQuery和ajax更改浏览器地址栏URL,无需重载页面[重复]

时间:2021-12-09 18:05:02

This question already has an answer here:

这个问题已经有了答案:

Change browser address bar URL with jQuery without reloading For example,

使用jQuery修改浏览器地址栏URL,无需重载,

www.mywebsite/list.php?page=1

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

on click change address bar ?id=123 etc...

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

3 个解决方案

#1


5  

not possible at all to change the url or even query string of the browser without reloading only part you can change without refresh is #hash part of the url till html4

根本不可能更改url,甚至不需要重新加载浏览器的查询字符串,只要不刷新就可以更改的部分是url的#哈希部分,直到html4。

But in html 5 some kind of url change can be done by the new HISTORY API give it a try

但是在html 5中,一些url更改可以通过新的HISTORY API来完成,请尝试一下

http://html5demos.com/history

http://html5demos.com/history

#2


2  

You can not. If you try to do it like this for example:

你不能。如果你试着这样做,比如:

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

It will reload the page. What you can do is change the hash

它将重新加载页面。你能做的就是改变散列

document.location.hash= "#123"

or

document.location.hash= "#i=123

And then write a simple parsor using split to grab the data you need. Similar question you should have a look at.

然后编写一个简单的parsor,使用split来获取所需的数据。类似的问题你应该看看。

#3


2  

jQuery: pjax plugin may help you.

jQuery: pjax plugin可以帮助您。

#1


5  

not possible at all to change the url or even query string of the browser without reloading only part you can change without refresh is #hash part of the url till html4

根本不可能更改url,甚至不需要重新加载浏览器的查询字符串,只要不刷新就可以更改的部分是url的#哈希部分,直到html4。

But in html 5 some kind of url change can be done by the new HISTORY API give it a try

但是在html 5中,一些url更改可以通过新的HISTORY API来完成,请尝试一下

http://html5demos.com/history

http://html5demos.com/history

#2


2  

You can not. If you try to do it like this for example:

你不能。如果你试着这样做,比如:

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

It will reload the page. What you can do is change the hash

它将重新加载页面。你能做的就是改变散列

document.location.hash= "#123"

or

document.location.hash= "#i=123

And then write a simple parsor using split to grab the data you need. Similar question you should have a look at.

然后编写一个简单的parsor,使用split来获取所需的数据。类似的问题你应该看看。

#3


2  

jQuery: pjax plugin may help you.

jQuery: pjax plugin可以帮助您。