| Report

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

Instead of:

onclick="yourCodeHere(); return false;"

Use this:

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

56 Replies

| Report
thx guy, it works, you save me :D
| Report
Yep, it worked here too. Thanks. RTB from Texas.
| Report
Oh... you are a life saver.
| Report
Thank you Thank you Thank you!!! from Singapore
| Report
thank you from Dealermade.com
| Report
thanks from paris!!!!
| Report
*Echoes* everyone's praises! Thank you from London!!!!!!
| Report
You are the best! I spent a hour trying to fixed not working return false javascript for image swapping...
| Report
Thanks from India you are a real genuis man Hatsoff to you
| Report
Thanx a Lot......
| Report
THANKS
| Report
Thanks! return false; suddenly stopped working in this script I am working on and I have no idea why. This works perfectly.
| 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!
| 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.
| 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.
| 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.
| Report
HI you are great..thanks for solution..keep posted the answers
| Report
Thanks from Bangalore
| Report
not only is this a bug in ie7 its in ie8 as well
| Report
Works great! Thanks a lot from Norway ;-)
| Report
Thanks a lot. From Australia....
| Report
You're great! I struggled with this problem for 3 days but after I used your fix, everything runs awesome. thanks a bunch!
| Report
doesn't work in firefox after you insert that code..
| Report
you're the man!
| 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
| Report
read Anonym150771 ...
| Report
I have been searching for this for HOOOOOOOOOOURS.
Thanks from Romania!!!
| Report
Thanks from Turkey..
| Report
Great stuff. Thanx a lot from Germany
| Report
u r awesome..its workin g8
| Report
Thanks
| Report
Next
| Report
THANX from France !!!! I burnt my brain on this this case ...
| 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
| Report
Awesome! Works great for me, thanks so much!
| Report
OM FG UR MY MASYER! IE DONT WANNA WORK WITH THAT! THX THX THXXXXXX!@!!!!!!!!!!!!!!!!!!!!!!!!!!!
| Report
Thanks
| Report
it worked. tq from Malaysia =)
| 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; }
| Report
Great help man!!!!!!!!!!!!!!!
| Report
thanks for sharing this very useful. -patrick
| Report
Great!!! Thank you...
| Report
too good... Thnks
| Report
Thank you!! You are a god amongst men
| 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!!!!!!
| Report
THANKS MAN!
| Report
Thank you, from india, u r genious
| Report
OOOOOOHHHHH THANKS THANKS A LOT Brother
YOU ARE REALLY GREAT
A REAL SUPER CODER
| Report
great great great! I've been searching for hours for this :)
| Report
thanks you are the best, from Jordan
| Report
Thank you!! from Barcelona (Catalonia)
| Report
You are a f. life saver and light saber!
| 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
| Report
Thnx..You are a life saver..from India
| Report
Thanks from Austria
| Report
спасибо из рашки чо
 Anonym
No regstration needed to add reply
Insert: Picture