<a href..> and "*****" action at the same time?

SONYFX

Senior member
May 14, 2003
403
0
0

I am trying to have Javascript and link URL at the same time, so when user clicks the link it will have a popup first then direct to that link, what's wrong with the following?


<a href="cnn.com" onclick="javascript:alert("hi")">cnn.com</a>
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
I think the click event preempts the normal handling of the href. Just do it from within a javascript function. The property you want is document.location, or something like that.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Your example works fine for me in firefox. You should be able to control the cascading of the event manually by returning a value from the onclick:

Should always work:
<a href="foo" onclick="alert('hi'); return true;">foo</a>

Should never work:
<a href="foo" onclick="alert('hi'); return false;">foo</a>

I support the idea of not using document.location because that tends to get in the way of browser configurations that open up links in new tabs or windows (for instance, if you middle click on a link) and it also stops users from seeing where the link is taking them because it doesn't show up in the status bar.