By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,866 Members | 1,704 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,866 IT Pros & Developers. It's quick & easy.

Notice change of window.location.hash without polling

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.