当前位置:首页 > WEB前端 > HTML > 正文内容

前端:如何屏蔽审查元素,禁止修改页面代码

ZnanrHTML1604

众所周知,审查元素的情况下,大家都可以随机更改一部分页面的代码,

注入恶意JS等等,这种情况避免也不难,虽然还能看到一部分H5源码,但是无法修改

一、屏蔽F12 审查元素

document.onkeydown = function(){

    if(window.event && window.event.keyCode == 123) {
        alert("F12被禁用");
        event.keyCode=0;
        event.returnValue=false;
    }
    if(window.event && window.event.keyCode == 13) {
        window.event.keyCode = 505;
    }
    if(window.event && window.event.keyCode == 8) {
        alert(str+"\n请使用Del键进行字符的删除操作!");
        window.event.returnValue=false;
    }

}

除了屏蔽这个,我们还有其他有趣的设置:

二、屏蔽右键菜单

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;
}
}


这种很适合小说网站,毕竟版权珍贵,被别人随意copy走内容就不好了

六、屏蔽选中

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;
}
}


扫描二维码推送至手机访问。

版权声明:本文由Znanr发布,如需转载请注明出处。

本文链接:https://www.znanr.com/?id=13

标签: HTML

相关文章

防止页面内容被复制

防止页面内容被复制

第一种方法:当别人在网站复制文字的时候,复制成功后会有一个弹窗提示,提醒下复制的人要保留出处<script type="text/javascript">do...

HTML 点击复制

HTML 点击复制

<!DOCTYPE html> <html> <head>     <script type...

旧版的Html页面插入flash代码

旧版的Html页面插入flash代码

代码有很多种,我在这里总结了一下最平常的插入方 式,以便下回能够直接拿来使用。Html插入flash代码方法<object?classid=“clsid:d27cdb6e-ae6d-11cf-9...

根据html页面id找对应的Js文件

根据html页面id找对应的Js文件

找到对应id,然后按F12进入开发者模式,ctrl+shift+f打开全局搜索,输入id,就可以找到对应文件!...

HTML5轮播图片段

HTML5轮播图片段

<!DOCTYPE html> <html> <head>     <meta char...

网页中调用另外网页

网页中调用另外网页

     这个网页中调用另外网页的方法可以让别人的页面成为你的页面的一部分,一下子让你的网页的内容丰富起来,再也不要愁你的记数器走的慢了,效果怎么样,你一用就知道了!&l...