faqts : Computers : Programming : Languages : JavaScript : Event handling

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

22 of 66 people (33%) answered Yes
Recently 1 of 10 people (10%) answered Yes

Entry

How to disable right click in Opera ?

Nov 22nd, 2001 14:47
ASA Admin, Colin Fraser, Peter Ned,


ASA Admin.
This may be what you are after?
<!-- Paste this code into the HEAD of your HTML document  -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript1.1">
<!-- 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("Bugga off and stop right clicking!!!");
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>
or possibly this:-
<script>
<!--
function right(e) {
	if (document.layers && (e.which==3 || e.which==2))  {
		window.status="NO RIGHT CLICK ALLOWED!"
		return false;
	}
	else if (document.all && (event.button==2 || event.button==3)) {
		window.status="STILL RIGHT CLICKING HUH? CUT IT OUT!"
		openclosewindow()
		return false;
	}
}
function openclosewindow() {
	var windownews=window.open
("", "", "status=no,location=no,toolbar=no,menubar=no,resizable=no,scrol
lbars=no,width=50,height=50,top=20000,left=200");
	windownews.close()
}
if (document.all) {
	document.onmouseup=right;
	window.onmouseup=right;
}
if (document.layers) {
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=right;
}
//-->
</script>
One main problem with using this type of script is it is very anoying 
to visitors. They may be trying to save some highlighted text to  word 
file for reading later or anything at all. 
Basically it just p-sses them off and they wont come back and you can 
bet they will tell everyone they know not to go they. 
As for using it to protect your intellectual property, it is a waste of 
time and effort. Simply viewing your source code and saving the text 
file with the complete page in it will do the trick.  
Now you can encode your source by downloading the script from many 
script sites,if your that worried about someone else using your info, 
but once again a pain in the butt! 
You have to uncode your code to edit it blah blah and blah. If you were 
trying to protect images well that is pointless too, visitors can save 
the page with the images or find where YOU are referencing them from 
and reference them from there as well and use your valuable band width! 
(That is annoying at best as simply moving the images now again fixes 
that or renaming them.  
In Short
Dont use it! If you want to keep your valuable visitors comming back!
Use it! If you want to lose visitors and give little anoyance to 
experienced Masters.
Good Luck and Cheers 
ASA Admin.