J
Jonas Smithson
I have some JavaScript that turns a row of anchors ('a' tags with no
hrefs) into links by adding a href to each one. There are two ways I
know of to do this; they both seem to have identical results in every
browser I've tested:
myElement.href="foo.html";
or
myElement.setAttribute("href", "foo.html");
Either one works fine in Firefox and Safari; as the loop runs, you can
see a whole row of anchors (which previously looked like ordinary text
to the user) suddenly turn into clickable links. It's really pretty cool.
However, there's a slight problem in IE. (I work on a Mac but I've been
testing it in IE6 on an old PC.) The code works, but as IE adds the href
to each anchor, it also puts the resultant link into a hover (or
mouseover) state -- so the user would see a whole row of links in the
hover style, as though a bunch of ghostly mouse pointers were
simultaneously hovering over all of them. If I physically mouse over and
then off each link, they resume the normal link appearance and behave
normally from then on.
I've experimented a lot but could not find a way to get IE to stop
acting as though adding a href meant it should also issue a persistent
mouseover. For example, I tried, right after adding the href to each,
applying myElement.blur() -- not surprisingly, that did nothing, since
the problem appears to be a mouseover not a focus state. More hopefully,
I tried myElement.mouseout() -- which threw an unspecified error.
Unfortunately I don't know the IE event model (or, frankly, any event
model) well enough to know how to deal with the situation.
I eventually came up with a workaround by browser sniffing, forking the
code, and using outerHTML to replace the entire element, which then
necessitated that I add some other kludgy code -- it works but it's
really ugly JavaScript.
Does anyone know how to stop IE from issuing the bogus mouseover event
as it adds a href to each anchor? Or, if that's not possible, how to
issue a mouseout event immediately afterwards, to undo the hover state?
Thanks.
hrefs) into links by adding a href to each one. There are two ways I
know of to do this; they both seem to have identical results in every
browser I've tested:
myElement.href="foo.html";
or
myElement.setAttribute("href", "foo.html");
Either one works fine in Firefox and Safari; as the loop runs, you can
see a whole row of anchors (which previously looked like ordinary text
to the user) suddenly turn into clickable links. It's really pretty cool.
However, there's a slight problem in IE. (I work on a Mac but I've been
testing it in IE6 on an old PC.) The code works, but as IE adds the href
to each anchor, it also puts the resultant link into a hover (or
mouseover) state -- so the user would see a whole row of links in the
hover style, as though a bunch of ghostly mouse pointers were
simultaneously hovering over all of them. If I physically mouse over and
then off each link, they resume the normal link appearance and behave
normally from then on.
I've experimented a lot but could not find a way to get IE to stop
acting as though adding a href meant it should also issue a persistent
mouseover. For example, I tried, right after adding the href to each,
applying myElement.blur() -- not surprisingly, that did nothing, since
the problem appears to be a mouseover not a focus state. More hopefully,
I tried myElement.mouseout() -- which threw an unspecified error.
Unfortunately I don't know the IE event model (or, frankly, any event
model) well enough to know how to deal with the situation.
I eventually came up with a workaround by browser sniffing, forking the
code, and using outerHTML to replace the entire element, which then
necessitated that I add some other kludgy code -- it works but it's
really ugly JavaScript.
Does anyone know how to stop IE from issuing the bogus mouseover event
as it adds a href to each anchor? Or, if that's not possible, how to
issue a mouseout event immediately afterwards, to undo the hover state?
Thanks.