网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的范文:

 

标题 JavaScript禁止右键及粘贴复制
范文
    由于项目要求,有些文本框需要禁用掉右键和复制粘贴的功能,昨天刚刚用JS实现。
    view sourceprint?
    01 function click(e)
    02 {
    03 if (document.all)
    04 {
    05 if (event.button==1||event.button==2||event.button==3)
    06 {
    07 oncontextmenu='return false';
    08 }
    09 }
    10 if (document.layers)
    11 {
    12 if (e.which == 3)
    13 {
    14 oncontextmenu='return false';
    15 }
    16 }
    17 }
    18
    19 if (document.layers)
    20 {
    21 document.captureEvents(Event.MOUSEDOWN);
    22 }
    23 document.onmousedown=click;
    24 document.oncontextmenu = new Function("return false;")
    25
    26 var trxdyel=true
    27 var hotkey=17 /* hotkey即为热键的键值,是ASII码,这里99代表c键 */
    28 if (document.layers)
    29 document.captureEvents(Event.KEYDOWN)
    30 function gogo(e)
    31 {
    32 if (document.layers)
    33 {
    34 if (e.which==hotkey && trxdyel)
    35 {
    36 alert('操作错误.或许是您按错键了!');
    37 }
    38 }
    39 else if (document.all)
    40 {
    41 if (event.keyCode==hotkey&&trxdyel){ alert('操作错误.或许是您按错键了!'); }}
    42 }
    43
    44 document.onkeydown=gogo
    将以上JS代码写到JS文件中取名为xp.js并放入Script文件夹中,引用时需要注意设置Charset=“utf8”,不然提示出的信息会是乱码。页面引用:view sourceprint?1 <script src="../Script/xp.js" type="text/javascript" charset="utf8"></script>
随便看

 

在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/20 18:18:32