加入收藏 | 设为首页 | 会员中心 | 我要投稿 核心网 (https://www.hxwgxz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 创业 > 正文

网页禁止右键菜单与防止复制内容另存网页

发布时间:2018-08-22 11:24:14 所属栏目:创业 来源:站长网
导读:理由很简单,网站辛苦整理的内容不想被人容易copy了,当然针对的是普通用户,查看源文件这个禁止还不是很容易实现.只是禁止了右键菜单,禁止了一些键盘按键,及选中文本,另存网页基本功能. 首先禁止右键,使用了jquery,很简单: //禁止鼠标右键 $(document).bind(

理由很简单,网站辛苦整理的内容不想被人容易copy了,当然针对的是普通用户,查看源文件这个禁止还不是很容易实现.只是禁止了右键菜单,禁止了一些键盘按键,及选中文本,另存网页基本功能.

首先禁止右键,使用了jquery,很简单:

//禁止鼠标右键
$(document).bind("contextmenu", function(e) {
return false;
});
再就是可以禁止键盘按键:

<script type="text/javascript">
function key() {
if (event.shiftKey) {
window.close();
}
//禁止Shift
if (event.altKey) {
window.close();
}
//禁止Alt
if (event.ctrlKey) {
window.close();
}
//禁止Ctrl
return false;
}
document.onkeydown = key;

</script>

当然禁止了选取内容,上面就不需要了:

<!-- 禁止选中内容 -->
<script type="text/javascript">

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
}
</script>

再就是禁止网页另存了:

<!--禁止网页另存为: -->
<noscript>
<iframe src="/*"></iframe>
</noscript>

还有另外一种方法,除了禁止另存外,其它功能基本上搞定:

<body oncontextmenu="return false" ondragstart="return false" onselectstart="return false"
onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false"
onmouseup="document.selection.empty()">
直接加在body里.

基本上就是这么多,整理了一下。


提示:可修改后代码再运行!

(编辑:核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读