A
axlq
I'm trying to figure out how to make javascript set the scroll
position of a page to an anchor that's specified in the page URL.
You may ask, why? Doesn't the browser go there anyway when the URL
is loaded?
Yes, well, sort of. Dynamic HTML javascript activity that must
occur when the page loads messes up the scroll position in all
browsers except IE. (I'm contracting a bunch of expanded lists so
that javascript enabled browsers show a compressed clickable list,
and non-javascript browsers show a fully expanded list.) So I need
a way to re-set the position to the anchor specified in the URL.
I tried:
document.location.hash = location.hash;
or
window.location.hash = location.hash;
....but these result in the page freezing up before it finishes
loading -- which makes sense I guess (setting an object equal to
itself).
I also tried:
var hl = document.location.hash.substr(1,document.location.hash.length);
...[DHTML javascript goes here]...
document.getElementById(hl).focus();
....but this doesn't appear to have any effect. What should I be doing?
-Alex
position of a page to an anchor that's specified in the page URL.
You may ask, why? Doesn't the browser go there anyway when the URL
is loaded?
Yes, well, sort of. Dynamic HTML javascript activity that must
occur when the page loads messes up the scroll position in all
browsers except IE. (I'm contracting a bunch of expanded lists so
that javascript enabled browsers show a compressed clickable list,
and non-javascript browsers show a fully expanded list.) So I need
a way to re-set the position to the anchor specified in the URL.
I tried:
document.location.hash = location.hash;
or
window.location.hash = location.hash;
....but these result in the page freezing up before it finishes
loading -- which makes sense I guess (setting an object equal to
itself).
I also tried:
var hl = document.location.hash.substr(1,document.location.hash.length);
...[DHTML javascript goes here]...
document.getElementById(hl).focus();
....but this doesn't appear to have any effect. What should I be doing?
-Alex