# Javascript Anti View Source Kode Script Blog Website URL: https://scafe.my.id/2024/06/06/javascript-anti-view-source-kode-script-blog-website/ Date: 2024-06-06 Last modified: 2024-06-06 Author: Ronald Davincie --- [](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4b-gNQkAq6Gje2I3SC0KiJ4AmGLIb0KtgBSPwCoKd8zYiZumx2wLtkqFwJUMzzbFdMGvFJYznr0V0dEmJX4XA5BckN80JlHsxUzpgeg9diD8hLUEtbzWmpfZoiwRUgistbK4ytqLYwa9JJPmNb3GxJmicxQFq2BOnrByRMUlgXyqO7JsAIT1_l_CnY5TB/s122/InShot_20240422_022846035_copy_122x122.jpg) Preventing users from viewing the source code of a website is a challenging task because browsers are designed to display the source code to users. However, you can implement measures to discourage or make it more difficult for users to view the source code. Here are some strategies you can use: 1. **Disable Right Click:** This prevents users from right-clicking to view the source. 2. **Disable Keyboard Shortcuts:** Prevents the use of shortcuts like `Ctrl+U`, `Ctrl+Shift+I`, `F12`, etc. 3. **Obfuscate JavaScript Code:** Makes the code harder to read. 4. **Prevent Developer Tools:** Attempt to detect and block the opening of developer tools. Here’s a basic example combining these methods: “`html
This content is protected.
“` ### Explanation: 1. **Disable Right Click:** “`javascript document.addEventListener(‘contextmenu’, function(e) { e.preventDefault(); }); “` This prevents the context menu from appearing when the user right-clicks. 2. **Disable Keyboard Shortcuts:** “`javascript document.addEventListener(‘keydown’, function(e) { if (e.keyCode === 123 || (e.ctrlKey && e.shiftKey && e.keyCode === 73) || (e.ctrlKey && e.shiftKey && e.keyCode === 74) || (e.ctrlKey && e.keyCode === 85)) { e.preventDefault(); } }); “` This blocks the `F12` key, `Ctrl+Shift+I` (to open Developer Tools), `Ctrl+Shift+J` (to open the JavaScript Console), and `Ctrl+U` (to view the page source). 3. **Prevent Developer Tools:** “`javascript (function() { function detectDevTools(allow) { if (isNaN(+allow)) return; let start = +new Date(); debugger; let end = +new Date(); if (end – start > 100) { document.body.innerHTML = ‘