Method of forbidding to view web page source code

There are always novices asking,How to prohibit others to view their own web page source code?The answer is No,For the experienced, all methods are futile。

Method of forbidding to view web page source code

The common method is to add a similar pageJScode,Shielding keyboard and right mouse button。

document.onkeydown = function() {
	var e = window.event || arguments[0];
	if (e.keyCode == 123) {
		return false;
	} else if ((e.ctrlKey) && (e.shiftKey) && (e.keyCode == 73)) {
		return false;
	} else if ((e.ctrlKey) && (e.keyCode == 85)) {
		return false;
	} else if ((e.ctrlKey) && (e.keyCode == 83)) {
		return false;
// Screen the right mouse button
document.oncontextmenu = function() {
	return false;

上述code用下面的包裹起来之后,Do not display prompt information:

window.onload = function() {
// code

Another paragraphJScode,It can prevent the normal use of browser development tools

<script type="text/javascript">
((function() {
	var callbacks = [],
	timeLimit = 50,
	open = false;
	setInterval(loop, 1);
	return {
		addListener: function(fn) {
		cancleListenr: function(fn) {
			callbacks = callbacks.filter(function(v) {
				return v !== fn;
	function loop() {
		var startTime = new Date();
		if (new Date() - startTime > timeLimit) {
			if (!open) {
				callbacks.forEach(function(fn) {;
			open = true;
		} else {
			open = false;

.addListener(function() {


上述方法只要浏览器prohibitJSAll scripts will be invalid,Although there are still people trying to study this,But foxes andchrome众多一键prohibitJSExpansion makes these efforts meaningless。

There seems to be a more hidden way,When the browser development tool window is opened, the page size changes,adoptJSJudge the change of browser window,在开发工具中看不到源code,But after knowing the principle,It’s also a cover up…


Related Article
Gitee is unable to push the updated version. The error “updates were rejected” is prompted

There are some collaborative office development times,Or useGITVersion control is better,And some open source software can be downloaded and released Read more

Making energy flow effect with CSS animation and SVG

The final effect is as follows: the animation is divided into two steps making the running track Creating the DOM Read more

WordPress 3D rotating tag cloud

This 3D tag cloud is not the flash version of WP cumulus n years ago. This 3D rotating tag cloud Read more

Using wampserver tool to build local PHP + MySQL environment

No matter whether we use domestic space or foreign hosts, we prefer to go online after local debugging before setting Read more

Leave a Reply

Your email address will not be published. Required fields are marked *

To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image