禁止页面鼠标右键和选择的方法

<html>
<title>禁止页面鼠标右键和选择的方法(支持Firefox和IE浏览器)</title>
<script type="text/javascript">
   document.oncontextmenu=function(e){return false;}</script>
<style>
body{-moz-user-select:none;}
</style>
<body onselectstart="return false">
禁止页面鼠标右键和选择的方法(支持Firefox和IE浏览器),这个方法是最简洁最有效的方法了。
</body>
</html>

说明:

body onselectstart="return false"

是禁止IE浏览器鼠标选择文字 JavaScript代码是禁止网页鼠标右键的,支持Firefox和IE浏览器

document.oncontextmenu=function(e){return false;}

css中

-moz-user-select:none;

这部分是针对Firefox,禁止Firefox浏览器鼠标选择文字

//除掉默认事件,防止文本被选择
window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
posted @ 2012-02-26 14:01  mfylee  阅读(906)  评论(0编辑  收藏  举报