For example we have a link say:
Clicking this link will show an alert saying “Hello” but will then move to http://www.example.com/.
To prevent this behavior first we will capture the eventobject and use its method preventDefault():
The above will work fine in Firefox, Chrome, Safari and Opera but does not work in IE instead IE provides a property of event object named returnValue, setting this to false resolves the issue:
Again this works fine with IE, Chrome, Safari, Opera but does not work with Firefox. So the right way is to take care of both i.e. IE and Firefox :
<a href="http://www.example.com/" onclick="alert('Hello');if(event.preventDefault) event.preventDefault(); else event.returnValue = false;" >Say Hello</a>