I've got a page full of links to another page with anchors on the end (like this: index.html#anchor). On the page they point to, I have a script that is supposed to read where the anchor points to in order to display something.
On firefox it works perfectly, But I've noticed that IE seems to remove the #anchor from the end of the url, so the script can't grab the text. Is there a way around this, without any server side code?
How is it getting the url?
window.location.hash
should contain the contents of the hash.
I've tested the following code in IE 6, 7, and 8, and the correct hash is shown in the alert box in all cases.
<script type="text/javascript">
function showHash() {
var currentUrl = "" + document.location;
var hash = "";
var parts = currentUrl.split("#");
if (parts.length > 1) {
hash = parts[1];
}
alert("the current hash is: " + hash);
}
</script>
<input type="button" value="Show Hash" onclick="javascript: showHash();" />
Does that code work for you?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With