zoukankan      html  css  js  c++  java
  • 禁止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";
    });
    
  • 相关阅读:
    什么是经验
    Linux驱动开启调试信息
    insecticide|contradictions| at large|delay doing|
    timber|stain|compensate|
    whip|resist|patch|intimate|
    chop|divorce|harsh|mutual|compel|
    crack|erosion|strip|
    stack|session|fuss|anniversary
    abrupt|promising
    nevertheless|magnificent |prosperous|
  • 原文地址:https://www.cnblogs.com/boluofan/p/12488869.html
Copyright © 2011-2022 走看看