Tom Cole wrote on 25 sep 2006 in comp.lang.javascript
:
>
howfu...@gmail.com wrote:
>I have following code:
<a href="javascript:void(0)" onClick="if(confirm('Please click Yes to
proceed. Click No to
cancel')){location.href='http://www.someurl.com';}">some link</a>
Tests fine in IE7 and latest firefox but not in IE6.
Any help very much appreciated.
Why don't you try this:
<a href="http://www.someurl.com" onclick="return confirm('Please click
Yes to proceed. Click No to cancel.');">some link</a>
Looks a little cleaner to me and puts stuff where it belongs. And it
works in IE 6.0...
Indeed.
And for the "why":
It is a timing question if the void() executes first or the location.href.
One should never write code that acts like that,
but use proper "return false" in an <aonclick.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)