切换为不分页显示
【首页】 【建站杂谈】 主题:禁止查看源文件代码
字体:    回复
禁止查看源文件代码 
夏飘雪(2009-9-9 16:10:01)  点击:12644  回复:0  IP:121.24.174.*
禁止查看源文件有下面几种方式:

【锁定右键】

将网页中的<body>换为如下代码即可:
<body oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">

【拒绝另存为】

在<body>和</body>之间加入如下代码:
<noscript><iframe src="*"></iframe></noscript>

【防止被Frame框架】

<SCRIPT LANGUAGE=javascript> if (top.location != self.location)top.location=self.location; </SCRIPT>

【禁止查看源代码】

尽管通过以上方式屏蔽了右键查看源文件,拒绝了复制和另存,但通过工具栏的【查看】—【源文件】仍会使网页失锁!

要彻底禁止查看源文件,可通过零框架技术解决——将页面分为左右两帧,左帧的宽度为0,载入空页面文件。“null.htm”;右帧载入要保护代码的页面,框架面页为index.htm,代码如下:
<html>
<head>
<title>--☆--</title>
</head>
<frameset cols="0,*" frameborder="NO" border="0" framespacing="0">
<frame src="/null.htm" name="leftFrame" scrolling="NO" noresize>
<frame src="/index.html" name="mainFrame">
</frameset><noframes></noframes>
</html>

同时,已被锁定右键、禁止另存的主面页(原代码见上)命名为 “index.html”,再添如下代码,以防被独立打开:
<script language="javascript"> if(top==self)top.location="index.html" </script>

【防止被框架】

<SCRIPT language=javascript> if (top.location != self.location){top.location=self.location; }</SCRIPT>

【取消选取、防止复制】

<SCRIPT language=javascript>
window.ClearEvent=function()
{event.cancelBubble=false;
var sSrcTagName=event.srcElement.tagName.toLowerCase();
return (sSrcTagName=="textarea" || sSrcTagName=="input" || sSrcTagName=="select");}
window.ClearKey=function(){event.cancelBubble=false;var iKeyCode=event.keyCode;return !(iKeyCode==78 && event.ctrlKey);}
with (window.document){oncontextmenu=onselectstart=ondragstart=window.ClearEvent;onkeydown=window.ClearKey;}
</SCRIPT>
<BODY oncontextmenu=self.event.returnvalue=false onselectstart="return false">
<body onselectstart="return false">

【禁止粘贴】

onpaste="return false;"

【防止复制】

oncopy="return false;" oncut="return false;"

【关闭输入法】

<input style="ime-mode:disabled">

【加密源代码】

利用Html Guard等html代码加密软件对网页程序代码进行转换加密变成别人看不懂的乱码。

附录:
防止网站博客文章被非法复制、保存、另存为和查看源代码

1.整篇文章不能点右键、不能区域选择和不能复制。不过能查看源文件和下载该页。代码如下:
<body oncontextmenu='return false' ondragstart='return false' onselectstart ='return false' onselect='document.selection.empty()' oncopy='document.selection.empty()' onbeforecopy='return false' onmouseup='document.selection.empty()'>
以上Body的参数同样可以应用于表格Table、层Div等。

2.在<body> </body> 之间加入如下语句,则网页无法另存为:
<noscript><iframe src=*></iframe></noscript>
加入上述代码后,当执行“另存为”命令时,会弹出“保存网页时出错”的对话框。

防止通过浏览器菜单“查看源代码”:打开页面后清空数据

<script language="javascript">
function clear(){
Source=document.body.firstChild.data;
document.open();
document.close();
document.title="看不到源代码";
document.body.innerHTML=Source;
}
</script>
<body onload=clear()></body>
这招算是目前网上公布的防止查看源代码的方法中最好的了,当然了,要看还是办法的,比如在地址栏中输入“javascript:alert(document.documentElement.outerHTML); ”就可以查看当前网页的源代码了。

[返回]
[本主题共0回复 | 每页显示20回复]
 返回列表 跳至页首跳至页尾 放大字体 缩小字体
按用户名:    按标题:   按内容:       包括所有回复
【首页】→ 【建站杂谈】 回复:禁止查看源文件代码
帖子标题:
   未登录!    

您的权限:
发表回复:×
UBB功能:×
文件上传:×
 
风格选择:极速  古韵  宽屏  大字  |  图示说明: 24小时新发主题  最近被编辑的主题  超过24小时普通主题
页面执行时间:140.625毫秒 | 在线:5 今日:194 合计:3234856 | 清除COOKIE |