8

I want to add some GET parameters to the page URL. I am loading content like this:

$("#content").load("shop.pl #content .product", $.param({categ:1)}));

How can I change the URL to have the same parameter ?categ=1?

1
  • Not sure you can do it without changing the page. Commented Aug 5, 2011 at 11:30

3 Answers 3

12

You can use the HTML5 pushState API to achieve this. However, only the newest browsers support it and IE doesn't even support it yet in IE9. There was no way to do this previsouly. However, there is a convention that you would use location.hash to indicate a page which's state was modified by an ajax request. For more information on how to use url hashes to indicate state on your page you might want to have a look at this.

There is a library, History.js, which can be used for transition to pushState. It's API is very close to the pushState API, but it will transparently provide a hash fragement fallback if the browser does not support pushState.

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

2 Comments

+1 for same idea as me - only quicker (I was editing the question!) :-)
pushState API link is broken
3

Your content is being loaded via AJAX, so perhaps the URL should have it's hash fragment modified - see http://code.google.com/web/ajaxcrawling/docs/specification.html

2 Comments

OP wants to change GET parameters of the current website, not the hash part of the URL, I believe.
Yes, but this is not possible in browser that do not support the HTML5 pushState API, which are basicly all but the latest browsers. Manipulationg the hash fragment of an URL was by convention he way to go to indicate and restore the altered state of an webpage.
0

You can try to manipulate the visible URL using pushState() method (see documentation, you may wish to read also about onpopstate event).

That way you can change the URL in a way you wish.

Some demonstration on how to change URL without page reloading is here: http://html5demos.com/history

Comments

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.