• Skip to main content
  • Skip to primary sidebar
Making Different

Making Different

Create, Learn, Build or Fix

  • Tech
  • Business
  • Relationship
  • Health
  • Travel
You are here: Home / Web Development / JavaScript / How to Disable CTRL+U, CTRL+C and Right Click on a Webpage

How to Disable CTRL+U, CTRL+C and Right Click on a Webpage

July 21, 2014 by Nitin Maheta

DISABLE-CTRL-U-CTRL-C-AND-RIGHT-CLICK-ON-A-WEBPAGE-USING-JQUERY

In one of my previous posts, we saw how you could disable text selection on a web page that works based on CSS that ultimately prevents users from selecting any text from your webpage, but why should we do this?

You should do this to prevent people from stealing/copying your content. But there are many other ways to copy the content from a webpage, even if the section of text is disabled on your webpage.

So, alternately you can use a more robust javascript code that does not only disable the selection of text but also disables CTRL + U (can be used to see actual HTML code), CTRL+C (can be used to copy highlighted/selected text), and right-clicks (displays list of options to do something with the item such as view source, copy, paste, etc.) on your website/blog.

So now, let’s move to the tutorial of disabling CTRL+U, CTRL+C key, and right-click on your website/blog. In your blog’s HTML, search for the tag. Just above it, paste it below javascript code.

<script type='text/javascript'>
var isCtrl = false;
document.onkeyup=function(e)
{
if(e.which == 17)
isCtrl=false;
}
document.onkeydown=function(e)
{
if(e.which == 17)
isCtrl=true;
if((e.which == 85) || (e.which == 67) &amp;&amp; isCtrl == true)
{
// alert(&#8216;Keyboard shortcuts are cool!&#8217;);
return false;
}
}
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler(){
return false;
}
function mousehandler(e){
var myevent = (isNS) ? e : event;
var eventbutton = (isNS) ? myevent.which : myevent.button;
if((eventbutton==2)||(eventbutton==3)) return false;
}
document.oncontextmenu = mischandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
</script>

Now, save the change, and voila! You’ve successfully disabled these features from your webpage.



About Nitin Maheta

Nitin Maheta is editor in chief and webmaster of MakingDifferent Blog. You may reach him out on following social media:

Facebook | Twitter | Instagram

Primary Sidebar

Similar Posts

  • How to Prevent Embedding Website Inside An Iframe?

Random Posts

activate-whatsapp-video-call-on-pc

How to Activate Whatsapp Video Call on PC

By Tejas Maheta

Swing Copters

Swing Copters: The next addictive game by Flappy Bird’s creator Dong Nguyen!

By Tejas Maheta

Karma

What Is Karma And How Does It Work?

By Nitin Maheta

ganesh-chaturthi

Ganesh Chaturthi Festival | Ganpati Bappa Moriya!

By Nitin Maheta

The-Right-PayPal-Purpose-Code-For-Indian-Freelancers

The Right PayPal Purpose Code For Indian Freelancers

By Nitin Maheta

All categories | About us | Contact us | Privacy policy | Disclaimer | Write for Us | Dictionary | Sitemap

The owner of this site is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com.

© 2025 Making Different