1. 禁止页面右击
<script type="text/javascript">
document.onmousedown = function () {
if (event.button == 2) {
event.returnValue = false;
alert("右键被禁止啦!");
}
</script>
2. 禁止网页选择,复制,右击
- 方法一:页面body中加入
<body oncontextmenu="return false" onselectstart="return false" oncopy = "return false">
- 方法二:js代码实现
<script type="text/javascript">
document.oncontextmenu = function (evt) {
evt.preventDefault();
};
document.onselectstart = function (evt) {
evt.preventDefault();
};
</script>
3. 禁止网页另存为
测试不成功
<body>
...
<noscript><iframe src=*.html></iframe></noscript>
</body>
4. 测试DEMO
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>蒹葭</title>
<script type="text/javascript">
/*document.oncontextmenu = function (evt) {
evt.preventDefault();
}
document.onselectstart = function (evt) {
evt.preventDefault();
};*/
document.onmousedown = function () {
if (event.button == 2) {
event.returnValue = false;
alert("右键被禁止啦!");
}
}
</script>
</head>
<body oncontextmenu="return false" onselectstart="return false" oncopy="return false">
<div style="text-align: center;margin: 50px;">
<h1 class="shici-title">蒹葭</h1>
<div class="shici-info">
[先秦] <a href="#">诗经</a>
</div>
<div class="shici-content">
蒹葭苍苍,白露为霜。所谓伊人,在水一方。<br>
溯洄从之,道阻且长;溯游从之,宛在水中央。<br><br>
蒹葭凄凄,白露未晞[1]。所谓伊人,在水之湄。<br>
溯洄从之,道阻且跻;溯游从之,宛在水中坻。<br><br>
蒹葭采采,白露未已,所谓伊人,在水之涘[2]。<br>
溯洄从之,道阻且右;溯游从之,宛在水中沚[3]。
</div>
</div>
</body>
</html>