Prevent the default action for an event
by Rekha[ Edit ] 2008-03-14 08:51:38
Hi
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).Functions like e.stopPropagation and e.preventDefault will help you to do so.
Example:
<script>
function openPopup() {
var url = this.href;
window.open(url, "popup_id", "scrollbars,resizable,width=300,height=400");
return false;
}
window.onload = function() {
document.getElementById("popup").onclick=openPopup;
}
</script>
...