addEventListener or attachEvent
<html>
<head>
<title>Options</title>
<script type="text/javascript">
function openwin(e) {
if (typeof window.open != "undefined") {
var opened = window.open("http://www.google.com","","width=240,height=480");
if (typeof e.preventDefault != "undefined") {
e.preventDefault();
e.stopPropagation();
}
e.cancelBubble = true;
return false;
} else {
return true;
}
}
</script>
</head>
<body>
<a href="#" id="my">Go?</a>
<script type = "text/javascript">
var mslink = document.getElementById("my");
if (window.addEventListener) {
mslink.addEventListener("click",openwin,false);
} else {
mslink.attachEvent("onclick",openwin);
}
</script>
</body>
</html>
Related examples in the same category