如何在没有输入textarea和选择项目的情况下阻止文本选择 [英] how to block text selection without input textarea and select items

查看:153
本文介绍了如何在没有输入textarea和选择项目的情况下阻止文本选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在没有输入文本区域和选择项目的情况下阻止文本选择
i实际上具有在IE中有效但不在其他浏览器中的脚本,这里是:

How to block text selection without input textarea and select items i actually have the script that works in IE but not in other browsers, here it is:

 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!");}

 }

我需要在其他浏览器中以相同的方式工作,那里必须是一个准备好的脚本,只是无法在网上找到..

i need to work it the same way in other browsers, there must be a ready script, just couldnt find in net..

推荐答案

<div onmousedown='return false;' onselectstart='return false;'></div>

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

onmousedown disables the selection for Firefox, Safari, Opera, Chrome and most other web browsers, onselectstart for IE.

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

Though disabling text selection and context menus is very bad style and does not prevent the pro-users from selecting your text. Simply disabling JavaScript in their browsers enables the selection again.

这篇关于如何在没有输入textarea和选择项目的情况下阻止文本选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆