• No categories

Prevent right click and text selection on webpage

Hello everyone, today i am going to show you, how prevent the user from right clicking web page or selecting the text on web page and copy it. This can be achieved using little css and a javascript event handler function.
Sometimes we have requirement to disable Right Click context menu and Text selection of a web page from the user example pce san diego, so that the user cannot use the right click default context menu and also to disable text selection so that sensitive data could not be copied from the website.
To prevent the right click, simply add following to your body tag of page as given below-

<body oncontextmenu="return false">

To prevent the selection of text on web page, add following in your style sheet-

body {
-webkit-user-select: none;
-moz-user-select: -moz-none;
-ms-user-select: none;
user-select: none;


This is tested code in one of my website. It works in all latest browsers approx.

About the Author:

Comments are closed.