Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何禁用网页上的文本选择_Javascript_Html_Css - Fatal编程技术网

Javascript 如何禁用网页上的文本选择

Javascript 如何禁用网页上的文本选择,javascript,html,css,Javascript,Html,Css,我正在努力使网页非常本土化。 如何删除网页中的select、select all属性?您可以通过在正文标记oncontextmenu=“return false <body oncontextmenu="return false;"> 这对您有帮助吗 <div onselectstart="return false;" style="-moz-user-select: none;"> 禁用使用CSS选择每个元素 Chrome、Safari、Firefox、IE 1

我正在努力使网页非常本土化。
如何删除网页中的select、select all属性?

您可以通过在正文标记oncontextmenu=“return false

<body oncontextmenu="return false;">

这对您有帮助吗

<div onselectstart="return false;" style="-moz-user-select: none;">

禁用使用CSS选择每个元素 Chrome、Safari、Firefox、IE 10和iOS设备都支持这一点

编辑:如果希望
在Firefox中保持可选状态,请添加:

input,
textarea {
     -moz-user-select: text;
}
使用jQuery禁用上下文菜单
此JavaScript将禁用内容的选择、复制和粘贴 但若用户将页面保存到本地机器上,他们就可以用你们的代码“做任何”他们想做的事情

//disable cut copy past
var message = "";
function clickIE() { if (document.all) { (message); return false; } }
function clickNS(e) {
    if(document.layers || (document.getElementById && !document.all)) {
        if (e.which == 2 || e.which == 3) { (message); return false; }
    }
}
if (document.layers)
{ document.captureEvents(Event.MOUSEDOWN); document.onmousedown = clickNS; }
else { document.onmouseup = clickNS; document.oncontextmenu = clickIE; }
 document.oncontextmenu = new Function("return false")


//for disable select option
document.onselectstart = new Function('return false');
function dMDown(e) { return false; }
function dOClick() { return true; }
document.onmousedown = dMDown;
document.onclick = dOClick;
使用此代码


到目前为止,您得到了三个完全不同的答案:也许您应该更好地指定“本机”对您的确切含义,以及您想要删除的内容您试图做的是阻止用户通过拖动鼠标并复制文本或使用CTRL+A(Windows)来选择文本选择并复制所有内容,对吗?是的,正确。防止用户选择整个网页,而不仅仅是文本,所有内容webpage@Pavlo这不是它的副本。这是关于删除突出显示,这是关于删除从网页复制任何内容的可能性。因此,这是一个副本,但这是一个@selva Yes,
visibi字体
显示
用户选择
都是CSS属性。但是你不能“选择”它们,你只能用所谓的CSS声明来设置它们。检查我的答案。这是一个好的开始,但不能阻止全选(Windows中的CTRL+A)但是在我的测试中。被认为是一种不好的做法。很好。我使用了这个,但是没有
body
标记。当
body
标记已经应用于整个html时,有什么理由使用它吗?在wpf web browser中工作!而这段代码可能会回答这个问题,提供关于如何和/或为什么解决这个问题的附加上下文这个问题将提高答案的长期价值。节省我的时间。我不知道这在CSS中会如此简单。我尝试了一整天使用javascript,发现了这个问题。
$(document).on("contextmenu", function (event) { event.preventDefault(); });
//disable cut copy past
var message = "";
function clickIE() { if (document.all) { (message); return false; } }
function clickNS(e) {
    if(document.layers || (document.getElementById && !document.all)) {
        if (e.which == 2 || e.which == 3) { (message); return false; }
    }
}
if (document.layers)
{ document.captureEvents(Event.MOUSEDOWN); document.onmousedown = clickNS; }
else { document.onmouseup = clickNS; document.oncontextmenu = clickIE; }
 document.oncontextmenu = new Function("return false")


//for disable select option
document.onselectstart = new Function('return false');
function dMDown(e) { return false; }
function dOClick() { return true; }
document.onmousedown = dMDown;
document.onclick = dOClick;
body, html{     
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;  
}
element_name{
  -webkit-touch-callout: none; 
  -webkit-user-select: none;
  -khtml-user-select: none; 
  -moz-user-select: none;
  -ms-user-select: none; 
   user-select: none;
 }