Cross browser disable the user select (Ctrl + A)

冷暖自知 提交于 2019-12-12 10:26:43

问题


By default the user can drag and select the screen item / press CTRL + A ,all the item will be turn blue and blur (selected). However, is there any way to block this event? Thanks

Are there any simple way just like adding some restriction in browser or adding some attribute in body tag can solve the problem?


回答1:


user-select:none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;

Add Following user-select property to that element which you do not want to turn blue. Adding it to body will turn selectable or editable elements to not be selectable or editable. So, it is recommended to use it on specific elements e.g.

div, image, iframe {
    user-select:none;
    -moz-user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
}

Or You can See More on:

Documentation




回答2:


You can do it by using jquery

$(function(){   
$(document).keydown(function(objEvent) {        
    if (objEvent.ctrlKey) {          
        if (objEvent.keyCode == 65) {                         
            objEvent.disableTextSelect();
            return false;
        }            
    }        
});
});    

Hope it works,this code disable ctrl+a on browser



来源:https://stackoverflow.com/questions/14598070/cross-browser-disable-the-user-select-ctrl-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!