How to Disable Inspect Element on a Website

How To Disable Inspect Element On A Website

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission at no extra cost to you.

There are many reasons that would make one want to disable browsers from viewing the source codes of a website. Some being the need to improve security or for confidentiality.

Whichever the reason may be, in this article, we will show you two simple steps you can use to disable inspect element and view page source option on a website.

What you need

Carrying out this procedure is very simple and straightforward. You only need to have basic HTML and JavaScript knowledge, or at know how to copy lines of codes without making errors.

So let’s get to it!

Pro Tip: You can't completely disable Inspect element on a Website. But you can try the out snippets on this page.

Step 1 — Disable Mouse Right-Click Function on the Website

You can disable the mouse right-click function on the website by adding the following codes in the

<script></script>‘ tag:

document.addEventListener('contextmenu', function(e){

e.preventDefault();

});




You can also choose to display an alert whenever the visitors right-click their mouse button. To do this, you’ll use this edited version of the previous code:

document.addEventListener('contextmenu', function(e){

alert("Sorry, right click is disabled");

e.preventDefault();

});

 

Step 2 — Disabling the Shortcut Key Combination that Triggers the Inspect Element Tool

There are certain key combos that launch the inspect element tool of a browser. They are:

  1. “Ctrl+Shift+I” for ‘Inspect Element
  2. “Ctrl+Shift+J” for ‘Inspect Element‘ Console panel
  3. “Ctrl+Shift+C” for ‘Inspect Element‘ Elements panel
  4. “Ctrl+S” for Saving Website as HTML file
  5. “Ctrl+U” for ‘View Source Code

We will go ahead to disable them using this piece of code below, also by adding them to the ‘<script></script>’ tag.

cdocument.onkeydown = function(e) {
if(event.keyCode == 123) {
return false;
}
if(e.ctrlKey && e.shiftKey && e.keyCode == 'I'.charCodeAt(0)) {
return false;
}
if(e.ctrlKey && e.shiftKey && e.keyCode == 'C'.charCodeAt(0)) {
return false;
}
if(e.ctrlKey && e.shiftKey && e.keyCode == 'J'.charCodeAt(0)) {
return false;
}
if(e.ctrlKey && e.keyCode == 'U'.charCodeAt(0)) {
return false;
}
if(e.ctrlKey && e.keyCode == 'S'.charCodeAt(0)) {
return false;
}
}

All Done!

Disable right click on WordPress without a plugin

For those who don’t like to use plugins to add new features to their website and prefer to get things done using code modification, this is for you. You can use simple code snippet to disable the right click on your website thus blocking inspect element ability.

Locate the </body> tag. Then, just add the following JavaScript code:

<script type=”text/javascript

jQuery(document).ready(function () {

//Disable cut copy paste

jQuery(‘body’).bind(‘cut copy paste’, function (e) {

e.preventDefault();

});

//Disable mouse right click

jQuery(“body”).on(“contextmenu”,function(e){

return false;

});

});

</script>

Conclusion

Disabling of inspect element only works on the page where these codes are present. If you want it to ally to all web pages on the site, you should implement the codes inside the ‘<header></header>‘ tag, or somewhere that appears on all pages/posts in the website.

If make mistake, codes still need to be in the ‘<script></script>‘ tag, however, this tag will be placed inside the header. Just like this:

<header>

<script>

‘Line of codes’

</script>

</header>

Avoid inserting codes in the footer tags, this will mean that all contents will load before the script, thereby affecting user experience.

Also Read:

Remote Job Sites In Nigeria And How To Get Them
12+ Websites to Get Remote Jobs in Nigeria (2024)

Following the entire COVID-19 era, the demand for remote jobs in Nigeria has gradually increased to compete with the current standards in other developed countries. Aside from employees constantly looking for ways to make their work easier, remote jobs in

What Is Paypal Email Address And Id
What is PayPal Email Address and ID?

PayPal is a leading online banking and payment solution provider that provides an easier and faster means of sending and receiving money using a secured internet account. PayPal provides adequate security services to hide financial information such as bank account

Patent
How much is Patent in Nigeria?

The cost of obtaining a patent certificate in Nigeria depends on a number of factors the IP law firm handling the registration, what’s to be patented, and even the number of patents to be filled. Far and large, you want

How To Pay For Hostinger Web Hosting In Nigeria
How to Pay for Hostinger in Nigeria?

Paying for a hosting plan in Hostinger is not an easy task for Nigerians – the limitations placed on debit cards makes payment proceeds difficult for individuals and businesses that do a lot of transaction in foreign currencies. Nevertheless, we’ll

Microsoft Excel Components Explained
Microsoft Excel Components Explained

Microsoft Excel is an electronic spreadsheet. Electronic spreadsheets are application programs capable of analyzing, organizing, and storing data in a tabular form. The application can provide a digital simulation of paper accounting worksheets. Examples of electronic spreadsheets include Google sheets,

How To Sell On Facebook Marketplace In Nigeria
How to Sell on Facebook Marketplace in Nigeria

Back in 2021, Facebook launched the marketplace as a platform for Facebook users to buy and sell. The platform works pretty well for sellers and buyers in almost the same location. While the platform does not really facilitate any transactional

Remote Job Sites In Nigeria And How To Get Them
12+ Websites to Get Remote Jobs in Nigeria (2024)

Following the entire COVID-19 era, the demand for remote jobs in Nigeria has gradually increased to compete with the current standards in other developed countries. Aside from employees constantly looking for ways to make their work easier, remote jobs in

Most Popular Types Of Websites
13 Most Popular Types of Websites (2024)

It is incontestable that a well-designed website is a cornerstone of any successful business venture that craves to create a sold digital footprint. Your website is often the first interaction potential customers have with your brand. From corporate informational business

Can I Convert Png To Svg
Can I Convert PNG to SVG?

Yes, you can convert PNG to SVG. The test can be done with a variety of tools, some are free, while others are paid as the function comes as part of a more robust bundle of conversion and editing tasks.

How To Convert Figma To Wordpress Site
How To Convert Figma To WordPress Website 

The combination of Figma and WordPress is a recipe for success in web design and development. As both tech companies have quite a reputation for being the best in their respective fields. Figma is a powerful and intuitive vector-based design

How to Search a Website for a Word using Google?

One of the reasons we all love to use Google search is the vastness of the search engine when it comes to finding information on the world wide web. Websites are structured and designed differently, I have seen several websites