How to disable right click on a html or JSP page

There can be requirements when you do not want users of your web application to right-click and view the html source.
Put following snipped in your html/jsp page’s header and user won’t see right-click context menu.

<SCRIPT LANGUAGE="JavaScript">

	function ieClicked() {
		if (document.all) {
			return false;
		}
	}
	function firefoxClicked(e) {
		if(document.layers||(document.getElementById&&!document.all)) {
			if (e.which==2||e.which==3) {
				return false;
			}
		}
	}
	if (document.layers){
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=firefoxClicked;
	}else{
		document.onmouseup=firefoxClicked;
		document.oncontextmenu=ieClicked;
	}
	document.oncontextmenu=new Function("return false")

</script>
Advertisements

, , , , ,

  1. #1 by rajesh on January 11, 2013 - 11:15 am

    working fine .. tks a lot

  2. #2 by Navya on November 7, 2013 - 5:29 am

    Hi Thank U so much.. Its working great

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: