• 禁止f12及浏览器右键查看


    今天在一个网站看美剧时突然想下载下来,就想f12查看视频链接后下载。但发现每次f12或右键检查时都会跳转到一个提示页面,不让查看在线播放页面的控制台。觉得十分有用,就自己研究实现了下:
    1.禁止键盘f12打开控制台:`

    // 按键事件
    document.onkeydown = keyPress;
    function keyPress(event) {
    	event = event ? event : window.event;
    	var keyCode = event.which ? event.which : event.keyCode;
    	var keyEvent = get_key_event(keyCode);
    	if(keyCode == 123){//禁止键盘f12按键
    		window.event.cancelBubble = true;
    		window.event.returnValue = false;
    		//也可以在按f12后跳转到指定提示页面
    	}
    }
    

    上步只禁止了键盘点击f12,对鼠标右键检查打开控制台没有措施
    2.开启监听事件,在检查控制台打开后跳转提示页

    //检测控制台是否打开
    (function () {
    	'use strict';
    	var devtools = {
    		open: false,
    		orientation: null
    	};
    	var threshold = 160;
    	var emitEvent = function (state, orientation) {
    		window.dispatchEvent(new CustomEvent('devtoolschange', {
    			detail: {
    				open: state,
    				orientation: orientation
    			}
    		))
    	};
    	setInterval(function () {
    		var widthThreshold = window.outerWidth - window.innerWidth > threshold;
    		var heightThreshold = window.outerHeight - window.innerHeight > threshold;
    		var orientation = widthThreshold ? 'vertical' : 'horizontal';
    
    		if (!(heightThreshold && widthThreshold) &&
    		((window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) || widthThreshold || heightThreshold)) {
    			if (!devtools.open || devtools.orientation !== orientation) {
    				emitEvent(true, orientation)
    			}
    			devtools.open = true;
    			devtools.orientation = orientation
    		} else {
    			if (devtools.open) {
    				emitEvent(false, null)
    			}
    			devtools.open = false;
    			devtools.orientation = null
    		}
    	}, 500);
    	if (typeof module !== 'undefined' && module.exports) {
    		module.exports = devtools
    	} else {
    		window.devtools = devtools
    	}
    })();
    
    //开启监视器
    window.addEventListener('devtoolschange', function (e) {
    	if (e.detail.open) console.clear();
    	console.log('*******************')
    	//跳转到错误页
    	windows.location.href="correct.jsp";
    });
    
  • 相关阅读:
    java字符串的遍历以及字符串中各类字符的统计
    Java Jvm运行机制原理
    为什么面试要问 hashmap 的原理
    HashMap的实现原理
    redis两种持久化方式的优缺点
    2018No-java面试知识
    从架构演进的角度聊聊spring cloud都做了些什么?
    MySQL索引优化
    2018java面试知识汇总
    多线程—7种同步方法
  • 原文地址:https://www.cnblogs.com/boluofan/p/12488869.html
Copyright © 2020-2023  润新知