How to Disable all Hotkeys (Like F12, CTRL+U, CTRL+Shift+ C) on Website (Blogger, WordPress)
Do you want to disable all Hotkeys or shortcut keys like CTRL+ C, CTRL+U, CTRL+Shift+C etc on your Blogger and WordPress Website then this article is for you.
Disabling hotkeys on your website can help reduce unauthorized access to source code and discourage content copying. Although it’s impossible to fully prevent determined users from accessing your code, disabling common hotkeys can prevent casual users.
In this article, I will show you how to archive this using JavaScript code. This will work on Both Blogger and WordPress Website.
So, let’s start.
Let’s understand what are the Hotkeys and Their Usages
Hotkey | Usage |
---|---|
F12 | Opens Developer Tools. |
Ctrl+U | Views the page source. |
Ctrl+Shift+I | Opens Developer Tools. |
Ctrl+Shift+C | Activates Inspect Element tool. |
Ctrl+C | Copies selected content. |
Ctrl+P | Prints the current page. |
Ctrl+S | Saves the current page. |
Right-click | Opens the context menu for additional options. |
Why Disable Hotkeys?
Hotkeys like F12 and Ctrl+Shift+C allow users to open Developer Tools, while Ctrl+U lets them view the page source. By disabling these, you can:
Steps to disable Hotkeys on Website
You need to use the below code on your Website whether it is in Blogger, Wordpress or any other CMS platforms.
<style> #custom-notification { display: none; position: fixed; top: 20px; right: 20px; background-color: #f44336; color: white; padding: 15px; border-radius: 5px; z-index: 1000; font-family: Arial, sans-serif; font-size: 14px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); animation: slide-in 0.3s ease, slide-out 0.3s ease 2.7s forwards; } @keyframes slide-in { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } } @keyframes slide-out { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(100%); } } </style> <div id="custom-notification" style="display:none; position:fixed; top:20px; right:20px; background-color:#f44336; color:white; padding:15px; border-radius:5px; z-index:1000; box-shadow: 0 4px 6px rgba(0,0,0,0.1);"> Hotkey disabled. </div> <script> document.addEventListener('keydown', function (event) { // Block F12 if (event.key === 'F12') { event.preventDefault(); showCustomNotification('F12 is disabled on this site.'); } // Block Ctrl+U (View Source) if (event.ctrlKey && event.key === 'u') { event.preventDefault(); showCustomNotification('Ctrl+U is disabled on this site.'); } // Block Ctrl+Shift+I (DevTools) if (event.ctrlKey && event.shiftKey && event.key === 'I') { event.preventDefault(); showCustomNotification('Ctrl+Shift+I is disabled on this site.'); } if (event.ctrlKey && event.key === 'p') { event.preventDefault(); showCustomNotification('Printing is disabled on this site.'); } // Block Ctrl+C (Copy) if (event.ctrlKey && event.key === 'c') { event.preventDefault(); showCustomNotification('Copying content is disabled on this site.'); } // Block Ctrl+Shift+C (Inspect Element) if (event.ctrlKey && event.shiftKey && event.key === 'C') { event.preventDefault(); showCustomNotification('Ctrl+Shift+C is disabled on this site.'); } }); document.addEventListener('contextmenu', function (event) { event.preventDefault(); showCustomNotification('Right-click is disabled on this site.'); }); function showCustomNotification(message) { const notification = document.getElementById('custom-notification'); notification.textContent = message; notification.style.display = 'block'; // Hide the notification after 3 seconds setTimeout(() => { notification.style.display = 'none'; }, 3000); } </script>
This script blocks key combinations such as F12, Ctrl+U, Ctrl+Shift+I, and others.
Important Considerations
- Not Foolproof: Advanced users can bypass these restrictions by disabling JavaScript or using external tools. These measures are more of a deterrent than a complete solution.
- User Experience: Disabling hotkeys may frustrate legitimate users. Use this approach only if it is necessary.
- Server-Side Security: For sensitive data, always secure it server-side instead of relying solely on front-end measures.
Read Also:
Conclusion
Disabling hotkeys like F12, Ctrl+U, and Ctrl+Shift+C on your website can discourage casual users from accessing your source code or copying content.
By implementing the above steps, you can add a layer of protection to your website. Remember, these measures are not foolproof, and server-side security remains critical for protecting sensitive information.
Let me know if this code works on your website or not. Also let us know if you want any modification on the code.
Don’t forget to share this article with your friends who need this.