Site Moved

This site has been moved to a new location - Bin-Blog. All new post will appear at the new location.

Bin-Blog

Default Action for an Event

There are many occasions when you have to override the default action of an event. For example, when a link is clicked, you want a popup to open(desired action) rather than going to the the page in the href attribute(default action). I will try to find the best way to do this.

Uses

This is most used in occasions like..

  • Opening a popup
  • Validating a form
  • Confirming a delete
  • And More

Solution

To see the detailed analysis of different methods to do this, take a look at the article 'Prevent the Default Action for an Event' at OpenJS.com. The final solution is given here....

if(!e) var e = window.event;

/* ... whatever ...*/

//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = false;

//e.stopPropagation works only in Firefox.
if (e.stopPropagation) {
 e.stopPropagation();
 e.preventDefault();
}

Filed Under...

0 Comments: