Click to See Complete Forum and Search --> : Event handler


neil9999
07-17-2003, 12:28 PM
Hi,

onclick is the event handler for left mouse click, what is the event handler for right mouse click?

Thanks,

Neil

AdamGundry
07-17-2003, 12:47 PM
According to the Netscape JS reference (http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/handlers.html#1119876), it is still onclick. You can test which button was pressed using the which property. (1 for left button, 3 for right button).

Adam

neil9999
07-18-2003, 10:18 AM
Thanks, but i don't understand how to specify '3'. Could you show me an example script, please, where when you right click on a link an alert appears?

Thanks again,

Neil

pyro
07-18-2003, 10:36 AM
This is pretty close to that: http://www.dynamicdrive.com/dynamicindex9/noright.htm

neil9999
07-18-2003, 10:53 AM
Thanks,

I tried adapting it to open a popup when you right click on the page.

What's wrong with this?

<html>

<head>
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
// End -->
</script>

<title>New Page 1</title>
<script language=JavaScript>
<!--

//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com


///////////////////////////////////
function clickIE4(){
if (event.button==2){
function NewWindow(this.href, name, 500, 500, yes);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
function NewWindow(this.href, name, 500, 500, yes);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")

// -->
</script>
</head>

<body>

</body>

</html>

Neil