Why does this not work in IE6

H

howfuchs

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.
 
H

howfuchs

Just to clarify, the confirm box pops up but using IE6 nothing happens
when I click 'OK'.
 
T

Tom Cole

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...
 
E

Evertjan.

Tom Cole wrote on 25 sep 2006 in comp.lang.javascript:
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 <a> onclick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top