Disable Right Click, Copy, Select Text, View Source Code

How to Disable Right Click, Copy, Select Text, View Source Code & dev tools in Blogger

Protect your content on blogger by securing your blog website by disabling all shortcuts and copy options. So If you want to secure your blog posts and pages from stealing your scripts and content then follow the instructions given below. By disabling shortcut keys like disable right-click, disable copy, disable view source shortcut, and more from the browser and use javascript as a content protection script for blogger or WordPress website you’ll be able to secure all your blog posts at once.

Many bloggers and website developers want to secure their content. By not allowing users/visitors of your website to do text selection, copy-paste option, disable right-click, disable view source option, and Developer Option shortcut keys. Don't worry Now, all of these are done by placing a piece of JavaScript code. It is simple to following the instructions given below and implementing all script in your website template.

How to Disable Right Click, Copy, Select Text, View Source Code & dev tools in Blogger
How to Disable Right Click, Copy, Select Text, View Source Code & dev tools in Blogger


To secure our website content and script we need to disable or blocking certain actions in the browser, by disabling four of the most common actions, such as:

  1. Disabling Text Selection and Copying,
  2. Disabling the Right-Click menu,
  3. Disable Viewing the Page Source Option (Shortcut key - Ctrl + U keypress in Chrome), and
  4. Disabling the Chrome Developer Tools (Shortcut keys - F 12 or Ctrl + Shift + I keypress combinations).

Why Disable right-click, view page source,text-selection & dev tools in Blogger website?

Because there are lots of content thieves on the internet to copy or manipulate or view secret code from your website. while most of the new bloggers don’t like to write content due to lack of knowledge and other reasons. So they start to steal other's content and many users can check secret links or scripts that are loaded on websites like live streaming links, important secret keys, etc.

In my case, our Technical Arp website we already use some of this to prevent our unique content, but let me tell you the Most obsessed part is Google takes no action to this. Even sometimes Google assigns a higher rank to that duplicate content. Sad Right!

Therefore, Disable the View page source option, text selection, disable right-click, and all other ways. So let's start to implement an All one Content Protection script for bloggers.

NOTE: The following guide gives you different codes that help with different actions like disabling the right-click or disable the view source option in the blogger website or any website, so you could either choose what you want or get all of them on your website template.

Useful Script for you: Automatic HTML Sitemap Page on the Blogger website 


How to Protect Content on Blogger - 4 Ways to Protect Content from Copy  

Secure your Blog post and Website content by using all below mention scripts. Read the proper guidance and use it in your template. We will be going to disable some actions from users or website visitors' web browsers to make it safe from getting stolen.

  1. How to Disable the Right-Click menu.
  2. Disabling Text Selection and Copying.
  3. How to Disable Viewing the Page Source Option (Shortcut key - Ctrl + U keypress in Chrome), and
  4. Block or Disabling the Chrome Developer Tools (Shortcut keys - F 12 or Ctrl + Shift + I keypress combinations).

We can implement All one content protection code for the blogger in two ways

1. Method 1 - By Putting Script in Gadget
2. Method 2 - Directly putting in the website template [I will prefer this one due to some reasons].

In Method 1

All the following codes will go into the Layout section in your Blogger Dashboard > Layout.

Create a new HTML/JavaScript Gadget and simply copy/paste the below code blocks to disable certain actions in the browser.

In Method 2

  1. Go to Blogger Dashboard
  2. Go to Theme/Template Section
  3. Click Edit HTML
  4. Now Find & Past Below SCRIPT Code before </body>

The following are JavaScript that helps to do our task.

JavaScript Code to Secure your Blog Post in Blogger or WordPress

The following are code blocks to disable Right Click, Text Selection, Copy function, Dev tools Shortcuts. So Copy and paste the below code blocks you want to use on your website.

How to Disable Right-Clicking

Use this code block to disable the right-clicking option.

CODE: 1 - without alert message 

<script type='text/javascript'> 
document.addEventListener('contextmenu', event => event.preventDefault()); 
</script>

CODE: 2 - with an alert message

<script type='text/javascript'> 
//<![CDATA[ 
var message="NoRightClicking is allowed in our website"; 
function arpianDisableClick() { 
if (document.all) { 
alert(message); //Remove this line if you don't want alert message 
return false; 
} 
} 
function arpianNoRightClick(e) { 
if (document.layers||(document.getElementById&&!document.all)) { 
if (e.which==2||e.which==3) { 
alert(message); //Remove this line if you don't want alert message 
return false;} 
} 
} 
if (document.layers) { 
document.captureEvents(Event.MOUSEDOWN); 
document.onmousedown=arpianNoRightClick; 
} else{ 
document.onmouseup=arpianNoRightClick; 
document.oncontextmenu=arpianDisableClick; 
} 
document.oncontextmenu=new Function("return false") 
//]]></script>

Use any one code block to disable right click on your website.

How to Disable Text Selection

For doing this we have many ways to do that but Use any one of these code blocks to disable text selection. When selection itself cannot happen, copying won’t be possible. Trying hitting Ctrl + C or Ctrl + V while browsing the blog and you’ll see the difference.

CODE: 1 - Using JavaScript


<script type='text/javascript'>
if (typeof document.onselectstart!='undefined' ) {
document.onselectstart=new Function (“return false” );
}
else {
document.onmousedown=new Function ('return false' );
document.onmouseup=new Function ('return true' );
}
</script>

CODE 2: Using jQuery


<script>
$('body').bind('copy cut drag drop', function (e) { e.preventDefault(); });
</script>

CODE 3: Using Pure CSS 

CODE 4: Advanced JavaScript 

Using this we can directly target Clipboard and manipulate text selection, if somehow the user is able to select text then also we can decide what their clipboard will copy. Great Right!

For more about Text Selection and Copy Paste Visit: Disable Text Selection and Copy Function from Blogger

How to Disable Viewing Page Source (Ctrl + U)

Use this code block in your template to disable the view source page shortcut option, the keyboard combination Ctrl + U, which is the keyboard shortcut to view page source. Although, this is an extra level of security, there are ways to get around this which we’ll see later in this guide.

CODE: With Alert message

// disable viewing page source
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
<script>
document.onkeydown = function(e) {
var message='Content is protected\nYou cannot view the page source.';
if (e.ctrlKey &&
(e.keyCode === 67 ||
e.keyCode === 86 ||
e.keyCode === 85 ||
e.keyCode === 117)) {
alert(message);
return false;
} else {
return true;
}
};
$(document).keypress('u',function(e) {
if(e.ctrlKey)
{
return false;
}
else
{
return true;
}
});
</script>

Remove the alert(message) line if you don't want the alert message to display.

How to Disable F12 Key – Dev Tools

Now Finally, use this code block if you want to disable the F12 key which lets the user access Dev Tools in the Chrome Web browser. 

Not just that, when you use this code block, it also disables the Ctrl + Shift + I keyboard the combination which is the same as pressing the F12 key to open Dev Tools.


//disable F12 Key and Ctrl + shift + I combination
<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js”></script>
<script>

$(document).keydown(function (event) {
var message = 'Content is protected\nYou cannot view the Dev Tools.';
if (event.keyCode == 123) { // Prevent F12
alert(message);
return false;
} else if (event.ctrlKey && event.shiftKey && event.keyCode == 73) { // Prevent Ctrl+Shift+I
alert(message);
return false;
}
});
</script>

Now time to put all in one block - All in One Content Protection JavaScript Code to secure website content.

Use the below code block to disable all actions mentioned in this post.


//disable right click menu
<script>

var message=”NoRightClicking is allowed in our website”;
function arpianDisableClick() {
if (document.all) {
alert(message); //Remove this line if you don’t want alert message
return false;
}
}
function arpianNoRightClick(e) {
if (document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {
alert(message); //Remove this line if you don’t want alert message
return false;}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=arpianNoRightClick;
} else{
document.onmouseup=arpianNoRightClick;
document.oncontextmenu=arpianDisableClick;
}
document.oncontextmenu=new Function(“return false”)

</script>

//disable Text Selection and Copying

<script type=’text/javascript’>
document.addEventListener(‘contextmenu’, event => event.preventDefault());
</script>

//==============================================================
// disable viewing page source
<script>
document.onkeydown = function(e) {
var message = “Content is protected\nYou cannot view the page source.”;
if (e.ctrlKey &&
(e.keyCode === 67 ||
e.keyCode === 86 ||
e.keyCode === 85 ||
e.keyCode === 117)) {
alert(message);
return false;
} else {
return true;
}
};
$(document).keypress(“u”,function(e) {
if(e.ctrlKey)
{
return false;
}
else
{
return true;
}
});

//=============================================================
//disable F12 Key and Ctrl + shift + I combination

$(document).keydown(function (event) {
var message = “Content is protected\nYou cannot view the Dev Tools.”;
if (event.keyCode == 123) { // Prevent F12
alert(message);
return false;
} else if (event.ctrlKey && event.shiftKey && event.keyCode == 73) { // Prevent Ctrl+Shift+I
alert(message);
return false;
}
});
</script>

NOTE: If you template is already using jquery library [ Mostly every template use it ] then remove  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> this jquery script as we must call it for one time.

That's all in this post. So now It's time for conclusion Right!

Very Useful Script: Install Anti Adblock Script in Blogger and Adblock Detection Script


In Conclusion of Disable Right Click, Copy, Select Text, View Source Code

Now you know all this code to secure your Blog Post and other content on your website. So Use it properly and If you face any problem then let us know from the below comment section.

Every Code is tested in Google Chrome and it works for me, and it works the same way for all the different browsers, except for page source and Chrome Dev Tools. Because different browser uses different Shortcut keys but will work in all popular browsers.

Thanks for Visting: Follow by Email and Bookmark Our Technical Arp Website for more such useful scripts.

Also, Know more about the following scripts:

Blogger Viral Wishing Website Script Collection Download

YouTube Thumbnail Downloader Script

Previous
Next Post »