// ===================== Security Enhancements ====================
GET IN TOUCH:(213) 537 - 3054
610 S. Broadway Suite 1001 Los Angeles, CA 90014

IT service, Computer Repair


Introduction

By default, browsers allow users to view HTML source code using "View Page Source" or developer tools. While you cannot 100% prevent determined users from seeing your code, you can discourage casual access.

Methods to Block Source Viewing

  • Disable Right Click:
    document.addEventListener('contextmenu', e => e.preventDefault());
  • Disable Keyboard Shortcuts:
    
    document.addEventListener('keydown', function(e) {
        if (e.ctrlKey && (e.key === 'U' || e.key === 'S') || e.key === 'F12') {
            e.preventDefault();
            alert('This action is disabled!');
        }
    });
                    
  • Obfuscate JavaScript: Convert your JS code into unreadable form using online obfuscators.

Full Script Block

  • Add the Script to your html Head
    
          // ===================== Security Enhancements =====================
    
        // Disable right-click
        document.addEventListener('contextmenu', function(e) {
            e.preventDefault();
        });
    
        // Disable common shortcuts: Ctrl+Shift+I, Ctrl+Shift+J, Ctrl+U, F12
        document.addEventListener('keydown', function(e) {
            var key = e.key.toUpperCase();
    
            if ((e.ctrlKey && e.shiftKey && (key === 'I' || key === 'J')) ||
                (e.ctrlKey && key === 'U') ||
                key === 'F12') {
                e.preventDefault();
                alert('This action is disabled.');
            }
        });
    
        // Optional: Obfuscated welcome div (Base64)
        (function(){
            var content = "PGRpdiBzdHlsZT0iZm9udC1zaXplOjIwcHg7Y29sb3I6IzAwMDA7bWFyZ2luOjIwcHg7Ij5XZWxjb21lIHRvIE15IE9iZnVzY2F0ZWQgUGFnZSE8L2Rpdj4=";
            /*document.write(atob(content));*/
        })();
    
        // Optional: Obfuscated JavaScript example
        (function(){
            var code = "Y29uc29sZS5sb2coJ0pvYlN0YXJ0ZWQhJyk7";
            eval(atob(code));
        })();
        
        
  • Obfuscate JavaScript: Convert your JS code into unreadable form using online obfuscators.

Additional Tips

  • Always use server-side processing for sensitive data. Client-side code is always visible.
  • Combine CSS & JS minification and obfuscation to make it harder to read.
  • Remember: These methods are deterrents, not absolute security.
tsc n-able