468,316 Members | 2,078 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,316 developers. It's quick & easy.

Notice change of window.location.hash without polling

Is it possible to notice a change of window.location.hash without
polling?

I'm working on a Ajax-platform (yes, inventing the wheel again) and
have finished almost everything except the support for
back/forward-buttons. The track I'm working on is "hidden frames" to
keep state in window.location.hash. I've seen some solutions along this
way that includes polling window.location for a change... which doesn't
comply with my otherwise strict event-driven design.

What I want is a way to notice the change between:
http://www.anysite.foo/index.html#{state_information}
and
http://www.anysite.foo/index.html#{new_state_information}
How can I catch this event in case the change is made by the browser's
back button?

/D

Nov 29 '05 #1
2 8430
Dennis Ålund said the following on 11/29/2005 5:42 AM:
Is it possible to notice a change of window.location.hash without
polling?
No.
I'm working on a Ajax-platform (yes, inventing the wheel again) and
have finished almost everything except the support for
back/forward-buttons.
That's not re-inventing the wheel, that is attempting to re-discover fire.

How will you determine when a person is at the beginning/end of the
history trail to know whether to grey out (disable) those buttons?

<snip>
What I want is a way to notice the change between:
http://www.anysite.foo/index.html#{state_information}
and
http://www.anysite.foo/index.html#{new_state_information}
How can I catch this event in case the change is made by the browser's
back button?


You can't without polling the URI.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 29 '05 #2
Thanks for putting it on the table... no good news though, but at least
I can stop searching now.
How will you determine when a person is at the beginning/end of the
history trail to know whether to grey out (disable) those buttons?
No need to worry about that. You simply feed a hidden IFRAME with the
application's URL + state information in the hash. Since only the hash
changes the page won't reload (which is very desirable). And these
URL-changes will also be valid browser history = back button gives me
previous state. That solves the problem of knowing when there is no
history to back up to; the browser takes care of it (which is beyond
JavaScript control anyway).
The only problem is how I'll know when the back-button was used...
polling isn't exactly on top ten of best solutions when it's supposed
to notice a button click with good response time :-/
That's not re-inventing the wheel, that is attempting to re-discover fire.


Anyhow, anyway, in modern days most men are proud every time they
manage to fire up the grill...

Nov 29 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Daniel Goldman | last post: by
2 posts views Thread by Timo | last post: by
7 posts views Thread by User | last post: by
3 posts views Thread by Paul Neave | last post: by
4 posts views Thread by Jeff Paffett | last post: by
18 posts views Thread by len.hartley | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.