4

I'm building a series of basic accordions for a project.

We want them to have static, linkable pages. So we've created invidividual pages for each of the open states as well.

For example,

/whoweare is the main slider.

But we have a sub slider located at /whoweare/whatwedo

What I'm looking to have done is, when a user clicks a header on /whoweare, the slider opens, and the url bar updates to /whoweare/whatwedo, but there is no actual redirect. The url location should simply change, nothing more.

I've tried using

window.location.replace($(this).attr('href'));
return false;

But that doesn't seem to have accomplished what I wanted, it still reloads onto a new page.

Any other suggestions?

Paul
  • 353
  • 5
  • 13
  • possible duplicate of [Changing browser's address bar without refreshing](http://stackoverflow.com/questions/352343/changing-browsers-address-bar-without-refreshing) – Paŭlo Ebermann Sep 04 '11 at 13:19

2 Answers2

11

You cannot change the URL without redirecting - it'd be a phishing nightmare (changing URL to that of a bank while staying on the phishing site, for example).

You can only manipulate the document hash - i.e. http://domain.com/#identifier - which is how Google, Facebook, etc. provide AJAX sites with browser history support.

Exact duplicate of #352343 Changing browser’s address bar without refreshing.

update: HTML5 now allows pushState, but only within the same domain.

Community
  • 1
  • 1
ceejayoz
  • 176,543
  • 40
  • 303
  • 368
0

Check out the Ben Alman's jQuery bbq plugin

$.bbq.pushState() - http://benalman.com/code/projects/jquery-bbq/examples/fragment-jquery-ui-tabs/

Greg
  • 8,574
  • 21
  • 67
  • 109