禁止查看源文件有下面几种方式

[url]
http://xiongbeyond.blog.sohu.com/155549034.html[/url]禁止查看源文件有下面几种方式:

【锁定左健和右键】

将网页中的<body>换为如下代码即可:

方法1:<body οncοntextmenu="return false;" onselectstart="return false;">


方法2:<body οncοntextmenu="return false" οndragstart="return false" onsele
ctstart ="return false"οnselect="document.selection.empty()" οncοpy="docume
nt.selection.empty()" onbeforecopy="returnfalse" οnmοuseup="document.select
ion.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){οncοntextmenu=onselectstart=οndragstart=wind
ow.ClearEvent;οnkeydοwn=window.ClearKey;}</SCRIPT>
<BODY οncοntextmenu=self.event.returnValue=false onsele
ctstart="return false"><body onselectstart="return false">


【禁止粘贴】

οnpaste="return false;"

【防止复制】

οncοpy="return false;" oncut="return false;"

【关闭输入法】

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

【加密源代码】

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

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

1.整篇文章不能点右键、不能区域选择和不能复制。不过能查看源文件和下载该页。代码如下:
<body οncοntextmenu='return false' οndragstart='return false'
onselectstart ='return false'οnselect='document.selection.emp
ty()' οncοpy='document.selection.empty()' onbeforecopy='return
false' οnmοuseup='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 οnlοad=clear()></body>
这招算是目前网上公布的防止查看源代码的方法中最好的了,当然了,要看还是办法的;

比如在地址栏中输入“javascript:alert(document.documentElement.outerHTML); ”

就可以查看当前网页的源代码了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值