Enhance the security of your website with this JavaScript solution that disables right-click, inspect element, view page source, and more.
Security through obscurity aims to obscure or restrict access to certain parts of your website's code or functionality. While this approach makes it more difficult for casual users to interact with or inspect elements, please note that it won't prevent persistent users from accessing your website's code or contents.
This script allows you to customize your website's security level with an interactive function that can be called directly from your site. Key features include:
- Disabling Right-Click Context Menu: Prevents users from accessing the context menu.
- Disabling Inspect Element Hotkeys: Blocks common hotkeys for inspecting elements:
- F12 (Inspect Element)
- Ctrl + Shift + I (Inspect Element)
- Ctrl + Shift + C (Copy Element)
- Ctrl + Shift + J (Open Console)
- Ctrl + U (View Page Source)
- Customizable Settings: Tailor the level of security to your needs with various options.
You have two options to implement this script, both of which function identically. Choose the regular version for general use or the obfuscated version for a harder-to-trace code.
Include the script in your HTML:
<script src="https://cdn.jsdelivr.net/gh/syntaxerror019/HTML-STO/lockdown.js"></script>
<script src="https://cdn.jsdelivr.net/gh/syntaxerror019/HTML-STO/ld.min.js"></script>
Add the following JavaScript code to initialize the security lockdown feature:
<script>
window.SecurityLockdown({
disableRightClick: true,
disableF12: true,
disableCtrlShiftI: true,
disableCtrlShiftC: true,
disableCtrlShiftJ: true,
disableCtrlU: true,
logAttempts: true
});
</script>
<script>
window.ZX983({
B1: true, // Disable right-click
T8: true, // Disable F12
R7: true, // Disable Ctrl + Shift + I
G4: true, // Disable Ctrl + Shift + C
Y5: true, // Disable Ctrl + Shift + J
K9: true, // Disable Ctrl + U
N0: true // Log attempts to the console
});
</script>
(Remove comments for full obfuscation. This is simply a documentation reference point)
You can customize the security features by adjusting the options in the SecurityLockdown
function. Here’s a breakdown of the available options:
- disableRightClick: (boolean) Enable/disable right-click functionality.
- disableF12: (boolean) Enable/disable F12 key for inspect element.
- disableCtrlShiftI: (boolean) Enable/disable Ctrl + Shift + I.
- disableCtrlShiftC: (boolean) Enable/disable Ctrl + Shift + C.
- disableCtrlShiftJ: (boolean) Enable/disable Ctrl + Shift + J.
- disableCtrlU: (boolean) Enable/disable Ctrl + U.
- logAttempts: (boolean) Log attempts to the console for monitoring.
While this script adds an additional layer of security, it should not be solely relied upon to protect sensitive data or code. It’s always advisable to implement robust security measures to safeguard your website and its contents.
This project is licensed under the MIT License. See the LICENSE file for details.
If you’d like to contribute to this project, feel free to submit a pull request or open an issue. Contributions and feedback are welcome!