PDA

View Full Version : Help: No Right Click (w/o alert box) JS script


Cyber Dragon
08-09-2002, 02:07 PM
The script below is for the "no right click", but it launches an alert box. How do I make it not launch an alert box? So that the right click is totally disabled?

<HEAD>

<SCRIPT LANGUAGE="JavaScript1.1">
<!-- Original: Martin Webb (martin@irt.org) -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function right(e) {
if (navigator.appName == 'Netscape' &&
(e.which == 3 || e.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' &&
(event.button == 2 || event.button == 3)) {
alert("Sorry, you do not have permission to right click.");
return false;
}
return true;
}

document.onmousedown=right;
document.onmouseup=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown=right;
window.onmouseup=right;
// End -->
</script>
</HEAD>

beetle
08-09-2002, 02:37 PM
Uh, just remove the alert() line....

<SCRIPT LANGUAGE="JavaScript1.1">
<!-- Original: Martin Webb (martin@irt.org) -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function right(e) {
if (navigator.appName == 'Netscape' &&
(e.which == 3 || e.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' &&
(event.button == 2 || event.button == 3)) {
alert("Sorry, you do not have permission to right click."); <-- Delete this sucka!
return false;
}
return true;
}

document.onmousedown=right;
document.onmouseup=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown=right;
window.onmouseup=right;
// End -->
</script>

boxer_1
08-09-2002, 04:06 PM
IMO, no right click scripts can detract from the overall perception of your page and are easily defeated. See http://continue.to/hope for more on protecting source code / page content ;) .

MUBNET
08-09-2002, 04:39 PM
If you use this code for only Internet Explorer, it's more practice;

<script language="JavaScript">
function dis(){
return false
}
document.oncontextmenu=dis
//If you want to disable the text selection
document.onstartselect=dis
</script>

Good works :thumbsup:

mhere
08-09-2002, 05:42 PM
Another example of silent right click can be found on:

www.dynamicdrive.com/dynamicindex9/noright3.htm


aakif.