js禁用右键菜单、选中、复制、剪切、粘贴

 //屏蔽右键菜单
     document.oncontextmenu = function (event) {
         if (window.event) {
             event = window.event;
         } try {
             var the = event.srcElement;
             if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
                 return false;
             }
             return true;
         } catch (e) {
             return false;
         }
     }

     //屏蔽粘贴
     document.onpaste = function (event) {
         if (window.event) {
             event = window.event;
         } try {
             var the = event.srcElement;
             if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
                 return false;
             }
             return true;
         } catch (e) {
             return false;
         }
     }

     //屏蔽复制
     document.oncopy = function (event) {
         if (window.event) {
             event = window.event;
         } try {
             var the = event.srcElement;
             if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
                 return false;
             }
             return true;
         } catch (e) {
             return false;
         }
     }

     //屏蔽剪切
     document.oncut = function (event) {
         if (window.event) {
             event = window.event;
         } try {
             var the = event.srcElement;
             if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
                 return false;
             }
             return true;
         } catch (e) {
             return false;
         }
     }

     //屏蔽选中
     document.onselectstart = function (event) {
         if (window.event) {
             event = window.event;
         } try {
             var the = event.srcElement;
             if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
                 return false;
             }
             return true;
         } catch (e) {
             return false;
         }
     }
上一篇:Qt 密码框不可选中、复制、粘贴、无右键菜单等


下一篇:webdriver的工作原理