如何在html中禁止文字的复制
4个回答
展开全部
可以禁止用户右键,使用js操作禁止,参考以下代码
<script type="text/javascript">
document.oncontextmenu=function(e){return false;}
</script>
<body onselectstart="return false">
也可以直接禁止用户选中页面从而实现禁止复制的目的,可以在css里面操作禁止,参考以下代码
body {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
以上两种方法都可实现禁止用户复制。
2016-09-18 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
一、禁止复制文字代码
<body leftmargin=0 topmargin=0 oncontextmenu='return false' ondragstart='return false' onselectstart ='return false' onselect='document.selection.empty()' oncopy='document.selection.empty()' onbeforecopy='return false' onmouseup='document.selection.empty()'>
二、真正的屏蔽鼠标右键
<script language="JavaScript">
<!--
if (window.Event)
document.captureEvents(Event.MOUSEUP);
function nocontextmenu()
{
event.cancelBubble = true
event.returnValue = false;
return false;
}
function norightclick(e)
{
if (window.Event)
{
if (e.which == 2 || e.which == 3)
return false;
}
else
if (event.button == 2 || event.button == 3)
{
event.cancelBubble = true
event.returnValue = false;
return false;
}
}
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
//-->
</script>
三、
<SCRIPT LANGUAGE=javascript>
function click() {alert('禁止左键复制!') }
function click1() {if (event.button==2) {alert('禁止右键点击~!') }}
function CtrlKeyDown(){if (event.ctrlKey) {alert('非法拷贝将损害您的系统!') }}
document.onkeydown=CtrlKeyDown;
document.onselectstart=click;
document.onmousedown=click1;
</SCRIPT>
把上面的代码放到</head> 与<body> 之间我已经调试过了 没问题
禁止保存网页
<NOSCRIPT><IFRAME src=Example132.htm></IFRAME></NOSCRIPT>
下面这段代码,就能搞定在网页中又禁止复制、又禁止键盘复制、还能禁止选择。
<script language="Javascript">
document.oncontextmenu=new Function("event.returnValue=false");
document.onselectstart=new Function("event.returnValue=false");
</script>
四、
onselect="document.selection.empty()"//禁止选中
oncopy="document.selection.empty()"//禁止复制
下面给你个演示:
<html>
<head><title>禁止右键和禁止使用复制键</title>
<script language="javascript">
function onKeyDown()
{
if ((event.keyCode==116)||(window.event.ctrlKey)||(window.event.shiftKey)||(event.keyCode==122))
{
event.keyCode=0;
event.returnValue=false;
}
}
function yxl() {
if(window.event.altKey)
{
window.event.returnValue=false;
}
}
document.onkeydown=yxl ;
</script>
</head>
<!--在网页中加上下面代码//-->
<body onkeydown="onKeyDown()" oncontextmenu="return false">
嘿嘿,把我复制走吧,我跟你拉!呵呵
</body>
</html>
五、
禁止复制代码
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body leftmargin=0 topmargin=0 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()">
<noscript><iframe src="/*>";</iframe></noscript>
<body leftmargin=0 topmargin=0 oncontextmenu='return false' ondragstart='return false' onselectstart ='return false' onselect='document.selection.empty()' oncopy='document.selection.empty()' onbeforecopy='return false' onmouseup='document.selection.empty()'>
二、真正的屏蔽鼠标右键
<script language="JavaScript">
<!--
if (window.Event)
document.captureEvents(Event.MOUSEUP);
function nocontextmenu()
{
event.cancelBubble = true
event.returnValue = false;
return false;
}
function norightclick(e)
{
if (window.Event)
{
if (e.which == 2 || e.which == 3)
return false;
}
else
if (event.button == 2 || event.button == 3)
{
event.cancelBubble = true
event.returnValue = false;
return false;
}
}
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
//-->
</script>
三、
<SCRIPT LANGUAGE=javascript>
function click() {alert('禁止左键复制!') }
function click1() {if (event.button==2) {alert('禁止右键点击~!') }}
function CtrlKeyDown(){if (event.ctrlKey) {alert('非法拷贝将损害您的系统!') }}
document.onkeydown=CtrlKeyDown;
document.onselectstart=click;
document.onmousedown=click1;
</SCRIPT>
把上面的代码放到</head> 与<body> 之间我已经调试过了 没问题
禁止保存网页
<NOSCRIPT><IFRAME src=Example132.htm></IFRAME></NOSCRIPT>
下面这段代码,就能搞定在网页中又禁止复制、又禁止键盘复制、还能禁止选择。
<script language="Javascript">
document.oncontextmenu=new Function("event.returnValue=false");
document.onselectstart=new Function("event.returnValue=false");
</script>
四、
onselect="document.selection.empty()"//禁止选中
oncopy="document.selection.empty()"//禁止复制
下面给你个演示:
<html>
<head><title>禁止右键和禁止使用复制键</title>
<script language="javascript">
function onKeyDown()
{
if ((event.keyCode==116)||(window.event.ctrlKey)||(window.event.shiftKey)||(event.keyCode==122))
{
event.keyCode=0;
event.returnValue=false;
}
}
function yxl() {
if(window.event.altKey)
{
window.event.returnValue=false;
}
}
document.onkeydown=yxl ;
</script>
</head>
<!--在网页中加上下面代码//-->
<body onkeydown="onKeyDown()" oncontextmenu="return false">
嘿嘿,把我复制走吧,我跟你拉!呵呵
</body>
</html>
五、
禁止复制代码
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body leftmargin=0 topmargin=0 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()">
<noscript><iframe src="/*>";</iframe></noscript>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我知道的有以下几种:
通过样式来控制css代码:
选择器{
-moz-user-select: none;
-khtml-user-select: none;
user-select: none;
}通过HTML属性:
<div unselectable="on" onselectstart="return false;" style="-moz-user-select:none;">XXXXXXXXXX</div>
说明:
unselectable针对IE
onselectstart针对Chrome、Safari
-moz-user-select是firefox专有的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2016-09-18
展开全部
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 oncontextmenu="return false" ondragstart="return false" onselectstart="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询