当前位置:网站首页>Specific methods for JS to realize full screen display
Specific methods for JS to realize full screen display
2022-06-11 18:34:00 【Code handling】
In response to a small demand of the company recently , Need to put a html Full screen control of the page , It's simple, but I've never done it before , Let's practice today , The specific operation methods are recorded below .
html page
<div class="btns">
<button type="button" id="exitBtn" class="btn" onClick="exitFullscreen()"> Exit full screen </button>
<button type="button" id="btn" class="btn" onClick="fullScreen()"> Full screen </button>
</div>
/** Other content codes **/
To achieve full screen function code :
function fullScreen() {
var de = document.documentElement;
if (de.requestFullscreen) {
de.requestFullscreen();
} else if (de.mozRequestFullScreen) {
de.mozRequestFullScreen();
} else if (de.webkitRequestFullScreen) {
de.webkitRequestFullScreen();
}
}
Exit the full screen function code :
function exitFullscreen() {
if(document.exitFullscreen) {
document.exitFullscreen();
} else if(document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if(document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
There is one caveat : When in js Use in click An error will be reported when calling an event ,( I use Firefox )
$("#btn").click(fullScreen()) // Note that errors will be reported

After checking the information, we found that , Because... Is not called internally from a user generated event handler that is running briefly Element.mozRequestFullScreen(), So reject the full screen request . This is a security setting , So in a normal browser environment ( End user computers ) Is the right behavior . The solution can use a callback function to call a full screen function .
perhaps , You must be in Firefox etc. onClick Event calls this function .
<button type="button" id="btn" class="btn" onClick="fullScreen()"> Full screen </button>
Here we are , The basic full screen function is realized .
边栏推荐
- On the problem that the while loop condition in keil does not hold but cannot jump out
- Learn to use LSTM and IMDB comment data for emotion analysis training
- Quanzhi T3 development board (4-core arm cortex-a7) - detailed explanation of logo display during system startup
- Function and principle of key in V-for
- ubuntu 安装psql以及运行相关命令
- MMA-Self-defining function
- Signal processing and capture
- [C语言]用结构体把输入的指定分数范围内的学生输出
- Modern application of LDAP directory server
- Sorted circular linked list
猜你喜欢

使用mysql判断日期是星期几

Introduction to basic use and pit closure of BigDecimal

Niuke's brush question -- judgment of legal bracket sequence

全国院校MBA、EMBA、MPA、MEM、提前面试(预面试)时间批次已出(持续更新中)-文都管联院

Force deduction 23 questions, merging K ascending linked lists

合并多棵二叉搜索树

关于keil中,while循环条件不成立却无法跳出的问题

非递归实现二叉树的前、中、后序遍历

Niu Ke's question -- Fibonacci series

Niu Ke's questions -- two sorting methods
随机推荐
Force deduction 32 questions longest valid bracket
牛客刷题——part7
Common interview questions of network and concurrent programming
使用mysql判断日期是星期几
高性能架构设计
BigDecimal基本使用与闭坑介绍
01.电信_领域业务经验
信号的处理与捕捉
[c language] shift elements after sorting elements of an array
非递归实现二叉树的前、中、后序遍历
Niu Ke's question -- Fibonacci series
vim常用命令
网络和并发编程常见面试题
ACL 2022: is it no longer difficult to evaluate word polysemy? A new benchmark "dibimt"
EasyCwmp源码分析
Some thoughts on how to do a good job of operation and maintenance management
Monitoring loss functions using visdom
SA token single sign on SSO mode 2 URL redirection propagation session example
牛客刷题——二叉搜索树与双向链表
Force deduction 23 questions, merging K ascending linked lists