zoukankan      html  css  js  c++  java
  • OnContextMenu事件

    用oncontextmenu事件单禁用右键菜单

    onconTextmenu=window.event.returnValue=false;右键菜单禁用,用这个能够禁止复制。

     

    在<body>中增加属性代码:

    oncontextmenu="return false"              

    onselectstart="return false"                   禁止选中网页上的内容

    oncopy="return false"                           防复制用户在网页上选中的内容

     

    防止用户另存网页:

    利用<noscript><iframe src=*.html></iframe></noscript>标签,能防止网页的直接另存,但不能防止网页被人使用工具下载

    *为通配符。

    例1:

    <html>
    <head>
    <title>OnContextMenu事件</title>

    <script language="JavaScript">
    <!--

    function uFunction()

    {     document.all.infoDiv.innerHTML='你按下了鼠标右键,可是右键菜单不能 显示!';}

    function uFunction2()

    {    document.all.infoDiv.innerHTML='你按下了Ctrl+鼠标右键,能够 显示右键菜单。';}

    //-->

    </script>
    </head>

    <body oncontextmenu="if(!event.ctrlKey){uFunction();return false}else{uFunction2()}">

    <div id="infoDiv">你按下了鼠标右键,可是右键菜单不能 显示!<br>你按下了Ctrl+鼠标右键,能够显示右键菜单。
    </div></body>
    </html>

     

    例2:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html><head>
        <title>利用OnMousedown和OnContextmenu为表格加入鼠标左中右键单击的处理</title>
        <script type="text/javascript">
    //
    var keyArray = new Array(
        new Array(0, "右键"),
        new Array(1, "左键"),
        new Array(2, "右键"), // 測试在IE7中按右键是2,在Maxthon2.0正式版中是0
        new Array(3, "左键右键同一时候按"),//在IE7中我測试捕获不到,慎用
        new Array(4, "中键")
        //測试同一时候按两个键很多其它的表示
        //new Array(6, "中键右键同一时候按")
    );
    function Click()
    {
        var message = GetKeyMessage(event.button);
        alert(message);
        if (event.button == 2 || event.button == 0) //按右键,// 測试在IE7中按右键是2,在Maxthon2.0正式版中是0
        {
            //处理代码
        }
    }
    function GetKeyMessage(button)
    {
        for (var i = 0; i < keyArray.length; i++)
        {
            if (keyArray[i][0] == button)
            {
                return keyArray[i][1] + ", event.button = " + button;
            }
        }
        return "未知组合键, event.button = " + button;
    }
    </script>
    </head><body>
    <table cellpadding="0" cellspacing="0" border="1">
    <tr>
    <!--oncontextmenu="return false"屏蔽快捷菜单-->
        <td oncontextmenu="return false" onmousedown="Click()">请分别用左键、右键、中键、左键右键组合点这里測试</td>
    </tr>
    <tr>
        <td>这个表格没有处理,点这里没反应</td>
    </tr>
    </table>
    </body>
    </html>
  • 相关阅读:
    [LeetCode]2. Add Two Numbers链表相加
    Integration between Dynamics 365 and Dynamics 365 Finance and Operation
    向视图列添加自定义图标和提示信息 -- PowerApps / Dynamics365
    Update the Power Apps portals solution
    Migrate portal configuration
    Use variable to setup related components visible
    Loyalty management on Retail of Dynamic 365
    Modern Fluent UI controls in Power Apps
    Change screen size and orientation of a canvas app in Power App
    Communication Plan for Power Platform
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4011774.html
Copyright © 2011-2022 走看看