在A页面上有一个按钮btn,点击这个btn,会打开一个新的页面B,同时,这个B页面实现全屏显示。我在网上找了,有打开页面自动点击按钮的js,也有点击按钮实现全屏的js,但这两个功能通过一次点击我没实现。求助大佬,怎么让页面在打开的时候,自动触发F11按钮功能。
你题目的解答代码如下:(如有帮助,望采纳!谢谢! 点击我这个回答右上方的【采纳】按钮)
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title> 页面名称 </title>
</style>
</head>
<body>
<a href="https://www.csdn.net" id="openfullscreen">打开csdn</a>
<div style="overflow: hidden; width: 0; height: 0;">
<iframe src="" width="100%" height="100%" id="fullscreenIframe"></iframe>
</div>
<script type="text/javascript">
function fullscreen(id) {
var element = id?document.getElementById(id):document.body;
if(element.requestFullscreen){
return element.requestFullscreen();
}else if(element.webkitRequestFullScreen){
return element.webkitRequestFullScreen();
}else if(element.mozRequestFullScreen){
return element.mozRequestFullScreen();
}else{
return element.msRequestFullscreen();
}
}
document.getElementById("openfullscreen").addEventListener("click", function (e) {
var ifr = document.getElementById("fullscreenIframe");
ifr.src = this.href;
fullscreen("fullscreenIframe");
e.preventDefault();
}, false);
</script>
</body>
</html>
把两个按钮的代码贴出来看看