教程集 www.jiaochengji.com
教程集 >  脚本编程  >  javascript  >  正文 禁止查看源代码的三种方法示例

禁止查看源代码的三种方法示例

发布时间:2015-05-09   编辑:jiaochengji.com
分享下禁止查看网页源代码的三种方法,三个不同的实现代码,有需要的朋友参考下。

本节内容:
如何禁止查看源代码

只要在<head>和</head>之间加入以下代码,即可实现禁止查看网页源代码:(可以用鼠标右键试试)
 

复制代码 代码示例:
<SCRIPT language=javascript>
function click() {
if (event.button==2) {
alert('对不起,禁止使用此功能.')
}
}
document.onmousedown=click
</SCRIPT>

禁止网页内容复制\粘贴\另存为的方法。

1,禁止网页另存为:在<body>后面加入:
 

复制代码 代码示例:
<noscript>
<iframe src="*.htm"></iframe>
</noscript>

2,禁止网页内容复制.粘贴:在<body>中加入以下代码:
 

复制代码 代码示例:
<body   onmousemove=\HideMenu()\ oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">

3,<!--免右键开始!--><script language="JavaScript">
 

复制代码 代码示例:
function click(e) {
if (document.all) {
if (event.button==2||event.button==3) {
oncontextmenu='return false';
}
}
if (document.layers) {
if (e.which == 3) {
oncontextmenu='return false';
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
document.oncontextmenu = new Function("return false;")
</script><!--免右键结束!-->

您可能感兴趣的文章:
禁止查看源代码的三种方法示例
js禁止查看源代码
禁止输入中文的js代码
彻底禁止查看网页源代码实例详解
js禁止页面F5刷新 右键与后退的代码
javascript禁止网页右键的方法
js禁用鼠标右键菜单(加强版)
jquery禁用右键、文本选择及复制按键的代码
js禁止页面中右键的简单实例
javascript禁止页面操作(右键、复制、F5刷新)等代码

关键词: 禁止查看源代码   
[关闭]
~ ~