html5全屏后,无法用keypress或keydown监听到Esc按键

浏览器默认不让监听Esc键

我们有需要在Esc按键后触发事件。代码如下

	//监听窗口退出全屏解决无法监听Esc按键
	window.onresize = function(){
		if(!checkFull()){
		//要执行的动作
			$('#FullScreen').html('全屏');
		}
	}

	function checkFull(){
		var isFull =
			document.fullscreenElement ||
			document.mozFullScreenElement ||
			document.webkitFullscreenElement;
	//to fix : false || undefined == undefined
		if(isFull === undefined) isFull = false;
		return isFull;
	}

 

你可能感兴趣的:(html,javascript)