Click to See Complete Forum and Search --> : reading location.hash IE 6


craftymind
09-02-2003, 11:31 PM
IE 6 doesn't seem to be updating location.hash or location.href after using the back button.
This works in netscape and moz. but not IE.
http://www.mustardlab.com/developer/test/anchors.html

On the page I'm trying 3 different methods to set the hash
setting: location.hash = 'hash'
setting: location.href = 'anchors.html#hash'
setting: hash through regular link

JS will read the hash once it's been set, but hitting back doesn't seem to be updating the location object.
Any thoughts on how to get it to read the hash after hitting back?

Fang
09-03-2003, 01:51 AM
The "Back" button contains an array of the window.location.href not of the document
You need to give the full URL to window.location.href for the "back" button to work
Was this your intention?

craftymind
09-03-2003, 12:27 PM
I tried reading window.location.href and window.location.hash and that didn't work either.

Fang
09-03-2003, 12:38 PM
For security reasons you can not read this array.

craftymind
09-03-2003, 12:51 PM
I'm not trying to read the history array, I'm trying to read the current document.location. When you hit the back button the url location doesn't update.

pyro
09-03-2003, 12:54 PM
Can you post a link to an example of what you are talking about? Also, this (http://www.infinitypages.com/research/location.htm) might help.

Fang
09-03-2003, 01:11 PM
Are you not trying to go to a bookmark that does not exist?
Your code does cause an error in Mozilla.

craftymind
09-03-2003, 01:21 PM
pyro, there is a link in my first post refering to the problem. I have an interval running which displays the location.href and location.hash of the current page, when you click one of the buttons or links, the text fields update with the new href and hash information, but when hitting the back button, the hash and href don't update, interestingly enough, the link you gave me does update when hitting the back button.

craftymind
09-03-2003, 01:29 PM
looking at the link you posted further, it appears they are actually sending the browser to a new page, rather than sending the browser to an anchor within that page.

I need a method for finding out which anchor they are at after hitting the back button, without sending the current document to a new page everytime.


Fang, I'm not sure what you mean. I'm not trying to go to a bookmark, I just need to know what anchor the user is currently located at.

craftymind
09-03-2003, 01:32 PM
the code for teh page is just a timeout interval output location.href and location.hash


function startwatch(){
setTimeout(startwatch, 100);
document.getElementById("intervalcheck").value = i++;
document.getElementById("hashoutput").value = document.location.hash;
document.getElementById("hrefoutput").value = document.location.href;
}

Fang
09-03-2003, 01:55 PM
document.location.hash will give you the anchor.
The problem with IE appears to be the reference to "top".
Change "top" to "tops" and the problem disappears.