Reputation: 14233
<script>
function confirmDel(evt)
{var con =false;
con=confirm('Do you really want to remove this purchase?.');
if(con)
{
return true;
}else
{
event.preventDefault();
}
}
</script>
my html
<a title="View Log" onclick="return confirmDel(this);" href="index.php?mod=tech_support">delete</a>
above code works fine in chrome browser but fails in Mozilla .
but when i use return false
instead of event.preventDefault();
it works fine in both.
can anyone explain why this happens
Upvotes: 0
Views: 1005
Reputation: 60747
The problem is with event.preventDefault()
. The event you're passing is evt
, not event
. You have to use:
evt.preventDefault();
event.preventDefault()
works in Chrome because it mimics old IE behavior for backwards compatibility (just like it also has innerText
).
In old IE, the event object was window.event
. So calling event.preventDefault()
calls the global event object, which works in Chrome and IE, but not Firefox which doesn't implement this non-standard behavior.
Upvotes: 3