3

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) 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 ?

nathan gonzalez
  • 11,817
  • 4
  • 41
  • 57
genesis
  • 50,477
  • 20
  • 96
  • 125
  • 1
    You want to change it to the same value? – lonesomeday Jun 05 '11 at 21:59
  • Why are you using Ajax for this? The desired effect you are describing sounds like standard web navigation, i.e., user clicks a link, browser requests and displays the page associated with that link. – nnnnnn Jun 05 '11 at 23:48

4 Answers4

4

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

Fredrik
  • 2,016
  • 3
  • 15
  • 26
  • It really does work! but problem is, that when I open source code, after that change, I see soure code of that new page (so It's requesting it), but I would rather not to "download" that file again. How? I do use this right now: – genesis Jun 05 '11 at 22:06
  • I have never used the API myself so I don't really know. But I thought that it wouldn't request the new page, it would just change the address bar to the new url. I thought that if you wanted to request the new page you had to do an ajax call to that page aswell. – Fredrik Jun 05 '11 at 22:15
2

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

This is only available in newer browsers.

Paul Creasey
  • 28,321
  • 10
  • 54
  • 90
1

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)

genesis
  • 50,477
  • 20
  • 96
  • 125
0

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

Mohsen
  • 64,437
  • 34
  • 159
  • 186