开发者

How NOT to redirect when using window.document.href

开发者 https://www.devze.com 2023-03-10 08:27 出处:网络
Hey. I do use jQuery to \"replace\" content of page with new informations, but i\'Ve got a problem. I DO NOT WANT TO USE HASH!

Hey. I do use jQuery to "replace" content of page with new informations, but i'Ve got a problem.

I DO NOT WANT TO USE HASH!

So for example, I've got this page:

http://mydomain.com/

user clicks to "Cool page" and ajax sends request to:

http://mydomain.com/coolpage

and I want to change link (adress bar开发者_如何学C) to:

http://mydomain.com/coolpage

but when ajax request is sent, I can't change adress bar URL by JS. How could I do that, without HASH ?


It's only supported in some web browsers. It's a new technology in HTML5. You can read more about it here: https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history


This is possible with the new HTML5 browser history api, specifically, the pushState() method.

This is only available in newer browsers.


Got it!

It's so easy with jquery plugin (adress) Just look here and try it!

http://phpcode.eu/ajaxtest/

(feel free to use my code)


You can use history.js that use HTML5 history API if supported and use hash if not supported. Syntax is same as HTML5 (pushState()).

There is no way no avoid hash in older browser if you want to manipulate URL

0

精彩评论

暂无评论...
验证码 换一张
取 消