您的位置:首页 > Web前端 > JavaScript

js 禁止复制,另存为,打印,查看源文件

2011-08-26 13:07 453 查看
锁定右键

一点要锁定右键,这里是为了兼容所有的浏览器,尤其是FF,不然FF可以复制

<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()">

拒绝另存

在和之间加入如下代码:

<noscript><iframe src="/*>";</iframe></noscript>

禁止查看源代码

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

要彻底禁止查看源文件,可通过零框架技术解决——将页面分为左右两帧,左帧的宽度为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>

同时,框架分2部分 ,为了防止index.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>

禁止打印

<style>@media print{body{display:none}}</style>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: