18

I would like to know if it's possible to change the contents of the URL in the browser without reloading the page?

I use jQuery and Ajax to load new parts of my page. When I choose "product one", the direct link would be mysite.com/product1 and for "product two" would be mysite.com/product2, but I don't want to reload the site to these pages.

7 Answers 7

14

its now possible with HTML_5..

chack this link... http://www.spoiledmilk.dk/blog/?p=1922

also facebook and google using this tric beside Hash(#) attribute

Sign up to request clarification or add additional context in comments.

2 Comments

Great! For cross browser support you can use a library like history.js github.com/balupton/history.js
Blog post is not found
13

You will have to add hash # if you want to prevent page from reloading.

The css-tricks.com has an excellent screencast on that, have a look at:

Best Practices with Dynamic Content

Comments

7

just use this one

window.history.pushState("object or string", "Title", "/new-url");

1 Comment

Watch out for IE < 10: caniuse.com/#search=pushstate. Use a polyfill like history.js.
7

This is possible in HTML5. See a demo here.

You can change the URL to another URL within the same domain, but can not change the domain for security reasons.

See the history interface in HTML5 specification for details.

Comments

1

You CAN do that. Though likely you'll need a modern browser. Have a look at this page: http://www.20thingsilearned.com/ created by the Google Chrome team (I used Chrome 9 to read it). Changing pages doesn't reload the entire web page, but changes the URL.

Comments

1

Yes, it is possible using the HTML5 History API. Check this page and this example

Comments

-4

You can't. Only if you change the hash, like sAc told you.

But.. May I ask WHY?

5 Comments

I'm not the OP, but I find it useful when you change your content via ajax, and then your visitor wants to store the page he is looking at to bookmarks/send via email/ etc..
Like Yossarian said, that was one of my reasons. Also because the load of the page loading is less using ajax, and the loading of contens is better looking.
@Yossarian: I asked why he wants to use site.com/product, like the initial Q was (not hash). @Paul: if you change more than 4-50% of your page content, you may want to rethink your strategy, because the speed you will gain with page transfer will be canceled by the DOM operation time :)
Wrong answer. In HTML5 it is posible to do that.
@Sasa, agree. But try to do that in IE9 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.