lars
lars

Reputation: 99

How can I change the location.hash of a target window, without reloading the page?

I'm currently using one page to spawn a new window, with a timed playback URLs in it. Many of the pages it's loading respond to hash navigation. I'm doing this like:

window.open(url,"playback");

As we play through the URLs, we should see the page respond accordingly. The problem I've run into however, is that the window.open() call actually reloads the page when the hash is changed.

For instance, loading "pageA.htm", then "pageB.htm#tab2" works flawlessly. The issue however is that when I try to go from "pageB.htm#tab2" to "pageB.htm#tab3"; the page reloads (responding properly to hash) completely instead of just firing "onhashchange" as I'd expect.

Is there an alternative to window.open() that I should call for hash-only changes, that will prevent full page reload?

Edit: The final solution looks something like this:

playbackWindow = window.open(url,"playback");

Then when we want to change the hash:

playbackWindow.location.href = "poundIt";

Upvotes: 1

Views: 1329

Answers (2)

Pierre Wahlgren
Pierre Wahlgren

Reputation: 875

You can't use window.open to change the hash without reloading the page. Simply change the value of window.location.hash instead.

Upvotes: 2

Skerrvy
Skerrvy

Reputation: 912

window.location.hash = "This"; 

should do the trick.

Upvotes: 0

Related Questions