javascript:禁用文本选择 [英] javascript: Disable Text Select

查看:107
本文介绍了javascript:禁用文本选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用javascript来禁用我的网站上的文字选择。

I'm using javascript to disable text selection on my webiste.

代码为:

<script type="text/JavaScript">

function disableselect(e){
return false
}
function reEnable(){
return true
}
document.onselectstart=new Function ("return false")
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</script>

类似的脚本可以在这里找到: http://rainbow.arch.scriptmania.com/scripts/no_right_click.html

similar script can be found here:http://rainbow.arch.scriptmania.com/scripts/no_right_click.html

在我的本地主机上:所有浏览器(Firefox,Chrome,IE和Safari)运行良好。

On my localhost: ALL Browsers (Firefox, Chrome, IE and Safari) work great.

在我的实时网站上:好的除了Firefox。

On my Live site: all ok EXCEPT Firefox.

我的问题是:


  1. 是否有人建议为什么Firefox对于实时站点和本地主机的行为有所不同。注意:Javascript已启用。

  1. Does anyone have a suggestion as to why Firefox behaves differently for the live site and local host. note: Javascript is enabled.

也许我的脚本过于简单,所以我尝试了以下完全相同的结果: http://freeware.ke-zo.com/CODES/DisableRC.txt

Maybe my script is too simplistic so i tried the following with EXACTLY SAME Results: http://freeware.ke-zo.com/CODES/DisableRC.txt


推荐答案

只需使用此css方法:

Just use this css method:

body{
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

您可以在此处找到相同的答案:如何禁用使用CSS突出显示文本?

You can find the same answer here: How to disable text selection highlighting using CSS?

这篇关于javascript:禁用文本选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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