Jumping to dynamically created named anchors in IE (JavaScript)
-
This is driving me nuts. I have some JavaScript that creates a bunch of named anchors on-the-fly using code like this:
var a = document.createElement("a");
a.name = "my_anchor";
document.body.appendChild(a);Later on I have some code that will jump to the anchor, e.g.:
window.location = "#my_anchor";
Works fine in Firefox, Opera and Safari. In IE7 nothing happens - it acts as if the named anchor doesn't exist. Anyone ever come across this before?
Kicking squealing Gucci little piggy.
The Rob Blog -
This is driving me nuts. I have some JavaScript that creates a bunch of named anchors on-the-fly using code like this:
var a = document.createElement("a");
a.name = "my_anchor";
document.body.appendChild(a);Later on I have some code that will jump to the anchor, e.g.:
window.location = "#my_anchor";
Works fine in Firefox, Opera and Safari. In IE7 nothing happens - it acts as if the named anchor doesn't exist. Anyone ever come across this before?
Kicking squealing Gucci little piggy.
The Rob Blog -
I managed to reproduce this and have no idea why it doesn't work, theres obviously something fishy going on (well, it is IE after all). To get it to work I had to set the ID of the anchor instead.
a.id = "my_anchor";
Thanks! Yes, that works a treat in all the browsers I tried.
Kicking squealing Gucci little piggy.
The Rob Blog