如何在没有输入文本区域的情况下阻止文本选择并选择项目

Bat*_*Dor 3 javascript select internet-explorer textarea input

如何在没有输入 textarea 的情况下阻止文本选择并选择项目我实际上拥有在 IE 中有效但在其他浏览器中无效的脚本,这里是:

 var omitformtags=["input", "textarea", "select"]
 omitformtags=omitformtags.join("|")
 function disableselect(e){
  if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
   return false
  }
 function reEnable(){
   return true
  }

 if (typeof document.onselectstart!="undefined")
  document.onselectstart=new Function ("return false")
 else{
  document.onmousedown=disableselect
  document.onmouseup=reEnable
 }
  document.onmousedown=click;
  function click()
 {
  if ((event.button==2) || (event.button==3)) { alert("Yaz? Kopyalayamazs?n?z!");}

 }
Run Code Online (Sandbox Code Playgroud)

我需要在其他浏览器中以同样的方式工作,必须有一个现成的脚本,只是在网络中找不到..

acm*_*cme 5

<div onmousedown='return false;' onselectstart='return false;'></div>
Run Code Online (Sandbox Code Playgroud)

onmousedown 禁用 Firefox、Safari、Opera、Chrome 和大多数其他网络浏览器的选择,onselectstart 禁用 IE。

尽管禁用文本选择和上下文菜单是非常糟糕的风格,并且不会阻止专业用户选择您的文本。只需在浏览器中禁用 JavaScript 即可再次启用选择。