Click to See Complete Forum and Search --> : No "Right-Clicking" Here


fuxmyl
04-30-2003, 10:07 AM
I tried using this code to disable right clicking on a test page:

<script language=JavaScript>
<!--

//Disable right click script III- By Renigade (renigade@mediaone.net)
//For full source code, visit http://www.dynamicdrive.com

var message="";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false")
// -->
</script>



It doesnt' work, not on IE version 6 anyways. Does anybody out there have a better solution for this feature?

thanks

khalidali63
04-30-2003, 10:12 AM
its not a permanent solution,

its simply a nuisance,why bother with it...

kbocalet
04-30-2003, 10:33 AM
I haven't tested it with netscape but it works on IE.

<script LANGUAGE="JavaScript">
<!-- Original: Martin Webb (martin@irt.org) -->

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


function right(e)
{
&nbsp;&nbsp;if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;
&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert("Disabled Option.");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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;
</script>

I know there is an easier way with oncontextmenu, you should try to search for that on previous threads, I think I saw it yesterday but not really sure...

Karla

Shampie
04-30-2003, 12:14 PM
<script>
function click(e){if (document.all) if (event.button == 2) return false;if
(document.layers) if (e.which == 3) return false;}
function click2(){event.returnValue=false;return false;}if (document.layers)
document.captureEvents(Event.MOUSEDOWN);document.onmousedown=click;document.oncontextmenu=click2;
</script>

when users rightclicks nothing will happen. (no menu or any msg)