首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >通过一段JS代码简单防止别人扒自己的网页,精髓在后面!

通过一段JS代码简单防止别人扒自己的网页,精髓在后面!

作者头像
程序员纬度
发布2021-03-02 11:03:21
4.2K10
发布2021-03-02 11:03:21
举报
文章被收录于专栏:奇异维度奇异维度

简单防止别人扒自己的网页(精髓在最下面)

有个神奇的东西叫做审查元素,按下神奇的F12,就是见证奇迹的时刻。审查元素真的是一个强大功能,有的时候看中别人网站的某个样式做的比较好,按下F12审查元素来查看别人的代码,统统扒过来。那么如果防止别人查看自己网站的代码,扒代码呢,当然,也只是防新手而已~心理安慰~

一、防F12扒代码:按下F12关闭当前页面

使用方法:将代码添加到网页顶部或底部即可,高手一般能破解,哈哈。

<script>
function fuckyou(){
window.close(); //关闭当前窗口(防抽)  
window.location="about:blank"; //将当前窗口跳转置空白页  
}
function ck() {
console.profile();
console.profileEnd();
//我们判断一下profiles里面有没有东西,如果有,肯定有人按F12了,没错!!  
if(console.clear) { console.clear() };
if (typeof console.profiles =="object"){
return console.profiles.length > 0;
}
}
function hehe(){
if( (window.console && (console.firebug || console.table && /firebug/i.test(console.table()) )) || (typeof opera == 'object' && typeof opera.postError == 'function' && console.profile.length > 0)){
fuckyou();
}
if(typeof console.profiles =="object"&&console.profiles.length > 0){
fuckyou();
}
}
hehe();
window.onresize = function(){
if((window.outerHeight-window.innerHeight)>200)
//判断当前窗口内页高度和窗口高度,如果差值大于200,那么呵呵了!
fuckyou();
}
</script>

二、防F12扒代码:按下F12画面卡死

使用方法:将代码添加到网页顶部或底部即可,这个也能破解,感觉这个更牛一点。

<script type="text/Javascript">
function inlobase_noF12(){while(1){}}
function inlojv_console(){if((window.console&&(console.firebug||console.table&&/firebug/i.test(console.table())))||(typeof opera=="object"&&typeof opera.postError=="function"&&console.profile.length>0)){inlobase_noF12()}if(typeof console.profiles=="object"&&console.profiles.length>0){inlobase_noF12()}}inlojv_console();window.onresize=function(){if((window.outerHeight-window.innerHeight)>200){inlobase_noF12()}};
</script>

三、屏蔽各种扒站的可疑操作。

把这段js代码加到你网页上,即可屏蔽鼠标右键菜单、复制粘贴、选中等。

<script>
//屏蔽右键菜单 
document.oncontextmenu = function(event) {
if (window.event) {
event = window.event;
}

try {
var the = event.srcElement;
if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
return false;
}
return true;
} catch (e) {
return false;
}
}

//屏蔽粘贴 
document.onpaste = function(event) { 
if (window.event) {
event = window.event;
}
try {
var the = event.srcElement;
if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
return false;
}
return true; 
} catch (e) {
return false;
}
}

//屏蔽复制
document.oncopy = function(event) {
if (window.event) {
event = window.event;
}
try {
var the = event.srcElement;
if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
return false;
}
return true;
} catch (e) {
return false;
}
}

//屏蔽剪切
document.oncut = function(event) {
if (window.event) { 
event = window.event;
}
try {
var the = event.srcElement;
if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
return false;
}
return true;
} catch (e) {
return false;
}
}

//屏蔽选中
document.onselectstart = function(event) {
if (window.event) {
event = window.event;
}
try {
var the = event.srcElement;
if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
return false;
}
return true;
} catch (e) {
return false;
}
}
</script>

评论区留言即可查看本文精髓部分!

此处内容需要评论回复后方可阅读

版权声明:本站原创文章 通过一段JS代码简单防止别人扒自己的网页,精髓在后面! 由 小维 发表!

转载请注明:通过一段JS代码简单防止别人扒自己的网页,精髓在后面! - 小维的个人博客

部分素材来源于网络,如有侵权请联系删除!

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020 年 05 月,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 简单防止别人扒自己的网页(精髓在最下面)
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档