Hi,
I want to use an anchor tag to invoke some javascript and I've read that
it's bad form to use <a href="javascrip t:foo()">
I've read endless usenet posts and hint sites on the net, they all suggest
different things and I can't get any kind of consistency, and I can't find
any solution that works properly for IE, opera and mozilla.
many of the recommended solutions go something like this:
<a href="javascrip t:void(0);" onclick="foo()" />
this generates an <a> that looks like a hyperlink (good) and it invokes
foo() as well (also good). the problem is that if in function foo, I put
window.location .href = "some new url";
it just seems to get ignored. If I miss out the href altogether, the link
works but it's not formatted as a hyperlink.
All I'm trying to do is make something that looks like a normal hyperlink
but whereby I can build the URL with some javascript rather than having it
coded into the HTML, and I have to say it's driving me mad!!. any hints
gratefully received
Andy
I want to use an anchor tag to invoke some javascript and I've read that
it's bad form to use <a href="javascrip t:foo()">
I've read endless usenet posts and hint sites on the net, they all suggest
different things and I can't get any kind of consistency, and I can't find
any solution that works properly for IE, opera and mozilla.
many of the recommended solutions go something like this:
<a href="javascrip t:void(0);" onclick="foo()" />
this generates an <a> that looks like a hyperlink (good) and it invokes
foo() as well (also good). the problem is that if in function foo, I put
window.location .href = "some new url";
it just seems to get ignored. If I miss out the href altogether, the link
works but it's not formatted as a hyperlink.
All I'm trying to do is make something that looks like a normal hyperlink
but whereby I can build the URL with some javascript rather than having it
coded into the HTML, and I have to say it's driving me mad!!. any hints
gratefully received
Andy
Comment