You just wrote a great piece of HTML code, but you don’t want others to copy your source code. By some small tips below will help programmers hide HTML Code on their Website to avoid being copied by others.
Join the channel Telegram of the AnonyViet 👉 Link 👈 |
How to hide HTML Code from others viewsource
Disable Ctrl and F12 keys with javascript
The F12 key is used to Open Chrome’s Developer Tools (Chrome Developer Tools). Chrome Developer Tools provides a set of tools that you can use to view the source code and behavior of a website.
Keys Ctrl mainly used in combination with other keys to view web source code.
Eg:
Ctrl + S: It is used to save the entire web page.
Ctrl + U: It is used to open the web source code in a new tab.
You can use this code in the script tag to disable the Ctrl and F12 keys.
document.addEventListener("keydown", function (event){ if (event.ctrlKey){ event.preventDefault(); } if(event.keyCode == 123){ event.preventDefault(); } });
Disable right click using javascript
By right clicking on the website, it will give you the option to view and inspect the source code of the website.
You can use this code in script tag to disable right click.
document.addEventListener(‘contextmenu’,
event => event.preventDefault()
);
More advanced techniques
The above two ways are great for those who are not very technical or for some beginners to learn programming.
What about Web developers (technical experts)?
They can still view the web’s source code using a chrome extension, HTML blocker (BURP) or postman.
So how to hide Source Code?
You cannot hide your HTML Code in your browser because your browser needs the HTML source code to run and view the web page.
However, here are some other techniques to minimize web scraping or source code duplication:
- Use REACT JS to keep your code to a minimum.
- Use server-side rendering to change the structure of your code over time.
- Apply copyright act to legal action.
- Enable SSL certificates to encrypt data between client and server side.
Conclusion
If you hide the HTML Code on the Website, Google’s crawlers can still read that code, but certain parts, such as No-Follow and No-Index, will tell the crawler whether to website indexing or not.
“Hidden text or links in your content to manipulate Google search rankings could be considered deceptive practice and violate the Google Webmaster Guidelines.”
You can hide data from users but not from crawlers, but now bots can read all the source code on your site.
Besides, I think hiding the HTML Code is not a good idea. You may face some SEO problems in the future.