Notice change of window.location.hash without polling

D

Dennis Ålund

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
 
R

Randy Webb

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?

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.
 
D

Dennis Ålund

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top