JS 禁用粘贴功能

JavaScript028

JS 禁用粘贴功能,第1张

<!-- 禁止选择文本: -->

<script type="text/javascript">

var omitformtags=["input", "textarea", "select"]

omitformtags=omitformtags.join("|")

function disableselect(e){

if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)

return false

}

function reEnable(){

return true

}

if (typeof document.onselectstart!="undefined")

document.onselectstart=new Function ("return false")

else{

document.onmousedown=disableselect

document.onmouseup=reEnable

}

</script>

<!-- 禁用右键: -->

<script>

function stop(){

return false

}

document.oncontextmenu=stop

</script>

功能:禁止右键、禁选择、禁粘贴、禁shift、禁ctrl、禁alt

<script language="JavaScript">

<!--

function key(){

if(event.shiftKey){

window.close()}

//禁止Shift

if(event.altKey){

window.close()}

//禁止Alt

if(event.ctrlKey){

window.close()}

//禁止Ctrl

return false}

document.onkeydown=key

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>

<body onselectstart="return false"onpaste="return false">

方法

2:

在<body>中加入以下代码:

<body oncontextmenu="return false" onselectstart="return false">

<body oncontextmenu="event.returnValue=false" onselectstart="event.returnValue=false">

实质上,方法2与方法1是一样的。

法3:

如果只限制复制,可以在<body>加入以下代码:

<body oncopy="alert('对不起,禁止复制!')return false">

2、使菜单"文件"-"另存为"失效

如果只是禁止了右键和选择复制,别人还可以通过浏览器菜单中的"文件"-"另存为"拷贝文件。为了使拷

贝失效,可以在<body>与</body>之间加入以下代码:

<noscript>

<iframe src="*.htm"></iframe>

</noscript>

这样,用户在另存网页时,就会出现"无法保存Web页"的错误。