如何隐藏 HTML 页面的源代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25228476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to hide the source code of a HTML page
提问by Francis
I created an HTML page and now would like to hide the source code and encrypt it.
我创建了一个 HTML 页面,现在想隐藏源代码并对其进行加密。
How can I do that?
我怎样才能做到这一点?
回答by Francis UK
You can disable the right click, but that's a bad idea because expert minds can read anything from your page. You cannot totally hide the page source - this is not possible. Nothing is secure enough on the Internet.
您可以禁用右键单击,但这是一个坏主意,因为专家可以从您的页面读取任何内容。您不能完全隐藏页面源 - 这是不可能的。互联网上没有什么是足够安全的。
In any case, you can encrypt it and set a password. You can utilise this link - it will encrypt your HTML page with a password.
在任何情况下,您都可以对其进行加密并设置密码。您可以使用此链接 - 它将使用密码加密您的 HTML 页面。
First up, disable the right click, by writing out this script, right after the tag.
首先,通过在标记之后写出此脚本来禁用右键单击。
<SCRIPT language=JavaScript>
<!-- http://www.spacegun.co.uk -->
var message = "function disabled";
function rtclickcheck(keyp){ if (navigator.appName == "Netscape" && keyp.which == 3){ alert(message); return false; }
if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) { alert(message); return false; } }
document.onmousedown = rtclickcheck;
</SCRIPT>
Then, encrypt all of it, in this website, called 'AES encryption'.
然后,加密所有这些,在这个网站上,称为“AES 加密”。
Link - http://aesencryption.net/
链接 - http://aesencryption.net/
You need to set a password to decrypt it ....you choose the password.
你需要设置一个密码来解密它......你选择密码。
After encrypting it, you can just write a basic HTML page just putting into the <head>
tag once again the script to disable the right click, into the <body>
tag you code and hide everything just writing at top of the page <html hidden>
.
加密后,您只需编写一个基本的 HTML 页面,只需<head>
再次将脚本放入标签中即可禁用右键单击,放入<body>
您编码的标签中并隐藏仅在页面顶部写入的所有内容<html hidden>
。
Example
例子
<!DOCTYPE html>
<html hidden>
<head>
<SCRIPT language=JavaScript>
<!-- http://www.spacegun.co.uk -->
var message = "function disabled";
function rtclickcheck(keyp){ if (navigator.appName == "Netscape" && keyp.which == 3){ alert(message); return false; }
if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) { alert(message); return false; } }
document.onmousedown = rtclickcheck;
</SCRIPT>
</head>
<body>
--here, you put the encrypted code from the link above--
</body>
</html>
Where it is written var message = "function disabled";
you can write for example something like 'This page cannot be viewed' or something which will annoy most of the users and will just leave. ['This page is unavailable' and so on ....].
里面写到var message = "function disabled";
你可以写例如像“此页无法浏览”或一些东西,会惹恼大部分的用户,并会见好就收。['此页面不可用'等等......]。
Finally, you will see a blank page with a message coming up as soon as you right click the page. The message will be something like 'This page is no longer active'.
最后,只要您右键单击该页面,您就会看到一个带有消息的空白页面。该消息将类似于“此页面不再处于活动状态”。
Example
例子
<SCRIPT language=JavaScript>
<!-- http://www.spacegun.co.uk -->
var message = "**This page is no longer active**";
function rtclickcheck(keyp){ if (navigator.appName == "Netscape" && keyp.which == 3){ alert(message); return false; }
if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) { alert(message); return false; } }
document.onmousedown = rtclickcheck;
</SCRIPT>
I do know that one can remove the <html hidden>
or the Javascript scriptwith some add-ons such as Firebug but anyway you will need to decrypt the code with a password in order to see the real page.
Expert users might view the source code with a Brute Force attack, I think.
So, nothing is safe.
我确实知道可以使用一些附加组件(例如 Firebug)删除Javascript 脚本<html hidden>
或Javascript 脚本,但无论如何您都需要使用密码解密代码才能看到真实页面。我认为,专家用户可能会通过蛮力攻击查看源代码。所以,没有什么是安全的。
I found out an application that you need to instal on your computer. There is a feature in the Enterprise version but you must pay to get it. This feature is a tool which encrypt your HTML page creating an ultra-strong password encryption for HTML files using up to 384 bit keys for encryption [the link I wrote above uses up to 256 bit keys for encryption]. I have never tried it out, though, because it is not for free.
我发现了一个您需要在计算机上安装的应用程序。企业版中有一项功能,但您必须付费才能获得它。此功能是一种加密您的 HTML 页面的工具,使用最多 384 位密钥为 HTML 文件创建超强密码加密[我上面写的链接使用最多 256 位密钥进行加密]。不过,我从未尝试过,因为它不是免费的。
Anyway, the link of the software 'HTML Guardian' - http://www.protware.com/default.htmFor the feature about the encryption, merely click on 'Ultra-Strong HTML password protection' in the page.
无论如何,软件'HTML Guardian'的链接- http://www.protware.com/default.htm有关加密的功能,只需单击页面中的“超强HTML密码保护”即可。
回答by NaveenDA
You cannot hide the source code, but you can add some difficulties to see your source code by following way
您无法隐藏源代码,但您可以通过以下方式添加一些困难来查看您的源代码
1. Disable right-click:
1. 禁用右键单击:
<body oncontextmenu="return false">
2.Disable ctrl, u, F12 keys:
2.禁用ctrl、u、F12键:
<script type="text/javascript">
function mousehandler(e) {
var myevent = (isNS) ? e : event;
var eventbutton = (isNS) ? myevent.which : myevent.button;
if ((eventbutton == 2) || (eventbutton == 3)) return false;
}
document.oncontextmenu = mischandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
function disableCtrlKeyCombination(e) {
var forbiddenKeys = new Array("a", "s", "c", "x","u");
var key;
var isCtrl;
if (window.event) {
key = window.event.keyCode;
//IE
if (window.event.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}
else {
key = e.which;
//firefox
if (e.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}
if (isCtrl) {
for (i = 0; i < forbiddenKeys.length; i++) {
//case-insensitive comparation
if (forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase()) {
return false;
}
}
}
return true;
}
</script>
3. Add to lots of white spaces to before you staring your codes
3.在你开始你的代码之前添加大量的空格
it may fool someone
它可能会愚弄某人
回答by DominationD
There isn't really anyway to do it that would stop a someone who is sophisticated.
无论如何都没有办法阻止一个老练的人。