我正在尝试自动将Chrome切换到全屏,但它不起作用,这里是示例代码
<html>
<script src="jquery-1.9.1.min.js"></script>
<div>Full Screen Test</div>
<input id="fullScreentButton" type="button" value="toggle" onclick="enterFullScreen()">
<script type="text/javascript">
//enter the fullscreen on click, works.
function enterFullScreen(){
var element = document.getElementsByTagName('body')[0];
element.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
function enterFullScreenInJquery(){
$('#fullScreentButton').trigger('click');
}
//enter the fullscreen on startup, does not work
enterFullScreenInJquery();
</script>
如果我点击按钮,它可以工作,为什么jquery不起作用?
答案 0 :(得分:3)
全屏JavaScript API仅在用户交互期间有效,因此无法恶意使用。