怎样不让用户查看网页的JS代码?

本文提供了一个用于解密和查看网页源代码的工具,通过JavaScript实现了代码加密与解密的功能,便于用户研究复杂的JS代码。

方成的webExcel有300多k的js代码,都可以随便拿来研究

 

 

谁说不行的啊

                给你个宝:
<html>
<head>

<title> 源代码解密 </title>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<SCRIPT   LANGUAGE= "JavaScript ">
<!--   Begin
function   viewSource()   {
document.getSource.view.value= "Please   wait! ";
setTimeout( "document.getSource.view.value= 'View   Source! ' ",6000);
window.location.href=   "view-source: "   +   document.getSource.url.value;
return   false;
}
//     End   -->
</script>
</head>

<body   bgcolor= "#000000 "   text= "#999999 "   link= "#33FF33 "   vlink= "#33FF33 "   alink= "#33FF33 ">
<center>
<form   name=getSource   onSubmit= "return   viewSource(); ">
<font   size=2>   输入网址按查看钮   </font>
<input   type=text   name=url   value= "http:// ">
<input   type=submit   name=view   value= "查看 ">
</form>
</center>
<SCRIPT   language=JavaScript>
<!--
var   i=0;
var   ie=(document.all)?1:0;
var   ns=(document.layers)?1:0;

function   initStyleElements()   /*   Styles   for   Buttons   Init   */
{
var   c   =   document.pad;
if   (ie)
{
//c.text.style.backgroundColor= "#DDDDDD ";
c.compileIt.style.backgroundColor= "#C0C0A8 ";
c.compileIt.style.cursor= "hand ";
c.select.style.backgroundColor= "#C0C0A8 ";
c.select.style.cursor= "hand ";
c.view.style.backgroundColor= "#C0C0A8 ";
c.view.style.cursor= "hand ";
c.retur.style.backgroundColor= "#C0C0A8 ";
c.retur.style.cursor= "hand ";
c.clear.style.backgroundColor= "#C0C0A8 ";
c.clear.style.cursor= "hand ";
}
else   return;
}

/*   Buttons   Enlightment   of   "Compilation "   panel   */
function   LightOn(what)
{
if   (ie)   what.style.backgroundColor   =   '#E0E0D0 ';
else   return;
}
function   FocusOn(what)
{
if   (ie)   what.style.backgroundColor   =   '#EBEBEB ';
else   return;
}
function   LightOut(what)
{
if   (ie)   what.style.backgroundColor   =   '#C0C0A8 ';
else   return;
}
function   FocusOff(what)
{
if   (ie)   what.style.backgroundColor   =   '#DDDDDD ';
else   return;
}
/*   Buttons   Enlightment   of   "Compilation "   panel   */

function   generate()   /*   Generation   of   "Compilation "   */
{
code   =   document.pad.text.value;
if   (code)
{
document.pad.text.value= 'Compiling...Please   wait! ';
setTimeout( "compile() ",1000);
}
else   alert( '请先把需待加密的代码copy到此框中 ')
}
function   compile()   /*   The   "Compilation "   */
{
document.pad.text.value= ' ';
compilation=escape(code);
document.pad.text.value= " <script> \n <!--\ndocument.write(unescape(\ " "+compilation+ "\ "));\n//--> \n <\/script> ";
i++;
if   (i=1)   alert( "代码已编译1次! ");
else   alert( "代码已编译 "+i+ "次! ");
}
function   selectCode()   /*   Selecting   "Compilation "   for   Copying   */
{
if(document.pad.text.value.length> 0)
{
document.pad.text.focus();
document.pad.text.select();
}
else   alert( '无任何内容被选中! ')
}
function   preview()   /*   Preview   for   the   "Compilation "   */
{
if(document.pad.text.value.length> 0)
{
pr=window.open( " ", "Preview ", "scrollbars=1,menubar=1,status=1,width=700,height=320,left=50,top=110 ");
pr.document.write(document.pad.text.value);
}
else   alert( '无任何内容可供预览! ')
}
function   uncompile()   /*   Decompiling   a   "Compilation "   */
{
if   (document.pad.text.value.length> 0)
{
source=unescape(document.pad.text.value);
document.pad.text.value= " "+source+ " ";
}
else   alert( '请把需待还原的代码copy到此框中! ')
}
//   -->
</SCRIPT>

            <TABLE   border=0   cellPadding=0   cellSpacing=0   width= "100% ">
                <TBODY>
                <TR>
                    <TD   width= "100% ">
                        <FORM   method=post   name=pad   align= "center ">
                <div   align= "center ">
                    <TEXTAREA   cols=58   name=text   rows=20   style= "BACKGROUND-COLOR:   #ebebeb;   WIDTH:   95% "> </TEXTAREA>
                    <BR>
                    <INPUT   name=compileIt   onclick=generate()   onmouseout=LightOut(this)   onmouseover=LightOn(this)   type=button   value=加密>
                    <INPUT   name=select   onclick=selectCode()   onmouseout=LightOut(this)   onmouseover=LightOn(this)   type=button   value=选中>  
                    <INPUT   name=view   onclick=preview()   onmouseout=LightOut(this)   onmouseover=LightOn(this)   type=button   value=预览>  
                    <INPUT   name=retur   onclick=uncompile()   onmouseout=LightOut(this)   onmouseover=LightOn(this)   type=button   value=还原>  
                    <INPUT   name=clear   onmouseout=LightOut(this)   onmouseover=LightOn(this)   type=reset   value=清除>  
                </div>
            </FORM> </TD> </TR> </TBODY> </TABLE>
</body>
</html>

 

 

 

 

 

 

 

 

网页代码的保护是一个复杂的问题,特别是对那些包含敏感信息或独特设计的网站。尽管JavaScript可以用来实现一些基本的防护措施,但需要明确的是,没有技术可以保证100%的安全性。下面是一些通过JavaScript阻止用户查看网页代码的方法,以及一些增强防护的建议。 参考资源链接:[彻底禁止网页代码查看与安全防护策略](https://wenku.csdn.net/doc/papmxw3xo3?spm=1055.2569.3001.10343) 首先,我们可以使用JavaScript来阻止右键菜单的弹出。这是通过监听鼠标的点击事件,并在检测到右键点击时阻止事件的默认行为来实现的。例如: ```javascript document.addEventListener('contextmenu', function(e){ e.preventDefault(); alert('版权所有(C) ***'); }, false); ``` 这段代码将阻止用户通过右键菜单查看网页代码,但它不能阻止用户使用其他方法,比如通过快捷键或在浏览器的“查看”菜单中选择“源文件”来查看代码。 为了进一步增强安全防护,建议采取以下措施: 1. 使用服务器端编程语言(如ASP或JSP)动态生成网页内容,这样即使用户查看网页代码,也只会看到脚本执行后的HTML,而不是原始的脚本代码。 2. 利用现代浏览器的同源策略(Same-Origin Policy),确保敏感操作只能通过特定域名下的脚本发起。 3. 为网页内容实施版权保护措施,例如使用数字版权管理(DRM)技术。 4. 限制对敏感文件的直接访问,例如通过服务器配置使用户不能直接访问后缀为.js或.css的文件。 最终,尽管通过JavaScript可以提供一定的防护,但最有效的方法是结合使用客户端和服务器端的技术手段,以及合理的版权法律知识,来保护网站的源代码和内容。如果想更深入地了解这些策略和实现方法,可以参考资料《彻底禁止网页代码查看与安全防护策略》。 参考资源链接:[彻底禁止网页代码查看与安全防护策略](https://wenku.csdn.net/doc/papmxw3xo3?spm=1055.2569.3001.10343)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值