Javascript onclick return false does not work in IE6, IE7 - workaround

Anonym4051311/27/2007 11:49 AM Report
Instead of:

onclick="yourCodeHere(); return false;"

Use this:

onclick="yourCodeHere(); event.returnValue=false; return false;"

Answers

Add a answer ▾

Discussion

Anonym7748404/19/2008 10:22 PM Report
Yep, it worked here too. Thanks. RTB from Texas.
Anonym8869306/29/2008 08:08 AM Report
Thank you Thank you Thank you!!! from Singapore
Anonym8399309/29/2008 05:35 PM Report
*Echoes* everyone's praises! Thank you from London!!!!!!
Anonym8699310/15/2008 12:02 PM Report
You are the best! I spent a hour trying to fixed not working return false javascript for image swapping...
Anonym8700510/15/2008 12:53 PM Report
Thanks from India you are a real genuis man Hatsoff to you
Anonym13580905/22/2009 07:33 AM Report
Thanks! return false; suddenly stopped working in this script I am working on and I have no idea why. This works perfectly.
Anonym15077108/24/2009 11:53 AM Report
Thanks a lot! For some reason it didnt work this way: onclick="yourCodeHere(); event.returnValue=false; return false;"

So i changed the order and now its working!
onclick="event.returnValue=false; yourCodeHere(); return false;"

Thanks again!
Anonym15684109/30/2009 01:14 PM Report
Ridiculous assertion. Show us code from a real world situation with this wrong behavior. I can predict it will be a human error and not what you "think" you found out.
Anonym15684109/30/2009 01:15 PM Report
A page entitle "Javascript onclick return false does not work in IE6,
IE7 - workaround", which is contrary to years of practical experience
and so almost certainly untrue. Lets be very clear about this;
clicking the link in the following simple HMML page does not result in
navigation on IE 6 or 7 (with javascript enabled, of course).

<html>
<head>
<title></title>
</head>
<body>
<a href="http://www.google.com/" onclick="return false;">
Link to google
</a>
</body>
</html>

Some random assertion to the contrary does not change that, and in
fact seriously being into question the competence of the person making
that assertion.
Anonym15825210/05/2009 03:09 AM Report
"ridiculous assertion" et al..

There is a bug in IE 6 that is intermittent. The people above are perfectly sane and very frustrated like I am from having to chase down the solution to this problem. It appears on some installations of IE6/7, and in some circumstances only. I have a page where 2 different elements use the same onclick code, one element works as expected and one doesn't. Thanks to the fix above, they both work fine.
Anonym16019010/14/2009 12:16 AM Report
HI you are great..thanks for solution..keep posted the answers
Anonym19899504/04/2010 03:25 AM Report
You're great! I struggled with this problem for 3 days but after I used your fix, everything runs awesome. thanks a bunch!
Anonym20108804/14/2010 07:36 PM Report
doesn't work in firefox after you insert that code..
Anonym20584605/14/2010 12:34 PM Report
hi.. onclick="yourCodeHere(); event.returnValue=false; return false;"
for me this code is not working.. any other solution so that onclick works in IE6
Anonym21944008/23/2010 07:40 PM Report
I have been searching for this for HOOOOOOOOOOURS.
Thanks from Romania!!!
Anonym23535811/30/2010 03:08 PM Report
THANX from France !!!! I burnt my brain on this this case ...
Anonym24918002/14/2011 05:56 PM Report
Actually, there`s no bug, or at least not with that. If the return false doesn`t work, that`s because there`s an error in your function that interrupts the script and activate the link so you fail to see the error warning. Remove the href and you should notice IE`s error icon, fix the error or comment it out and you`ll see the return false will work as expected.

sanjuro, http://www.1up-games.com
Anonym25851604/04/2011 03:49 PM Report
OM FG UR MY MASYER! IE DONT WANNA WORK WITH THAT! THX THX THXXXXXX!@!!!!!!!!!!!!!!!!!!!!!!!!!!!
Anonym28309309/16/2011 11:09 PM Report
It fails on the event statement under FF 6.
I fixed it by preceeding it with an IE check:

if ( $.browser.msie ) { event.returnValue=false; }
Anonym31101801/17/2012 08:32 AM Report
I was really horrified and annoyed with this .. after years of working with javascript.. the simple code of preventing postback on button click does not work..
Thanks it works fine.. how about other browsers??
Let me see!!!!!!
Anonym39864303/20/2012 06:37 AM Report
OOOOOOHHHHH THANKS THANKS A LOT Brother
YOU ARE REALLY GREAT
A REAL SUPER CODER
Anonym42505405/27/2012 10:49 AM Report
great great great! I've been searching for hours for this :)
Anonym45455809/18/2012 11:31 AM Report
Thanks a lot for your solution..gr8 job <Subrat>

return false is equal to event.returnValue

but sometimes not work becoz of dom portability

for ex:-

OnClientClick="return confirm('Are you sure want to Delete this file?');" (Not working)


OnClientClick="event.returnValue=confirm('Are you sure want to Delete this file?');" (Working fine)

mail me subratnayak09@gmail.com
Add a question comment ▾