最近做了一个号称很炫的B/S展示软件,展示所用浏览器为Google Chrome。
要求展示时全屏,但是页面要有退出全屏按钮(液晶屏没有键盘)。
搜索实现方式几乎前篇一律,即两个JS函数一个实现全屏一个退出全屏:
function requestFullScreen(element)
{
if (element.requestFullscreen)
element.requestFullscreen();
else if (element.msRequestFullscreen)
element.msRequestFullscreen();
else if (element.mozRequestFullScreen)
element.mozRequestFullScreen();
else if (element.webkitRequestFullscreen)
element.webkitRequestFullscreen();
} function cancelFullScreen()
{
if (document.exitFullscreen)
document.exitFullscreen();
else if (document.msExitFullscreen)
document.msExitFullscreen();
else if (document.mozCancelFullScreen)
document.mozCancelFullScreen();
else if (document.webkitExitFullscreen)
document.webkitExitFullscreen();
}
但是在实际调用中发现cancelFullScreen只对requestFullScreen实现的全屏有效而对F11实现的全屏没有效果。
所以就想到使用requestFullScreen实现全屏,但是问题又来了requestFullScreen实现的全屏仅对当页有效,
在页面跳转时全屏效果就会消失,所以还是只能通过F11实现全屏。
又搜索其中一种退出方式为除了上面两个函数外又添加两个函数:
function isFullScreen()
{
return (document.fullScreenElement && document.fullScreenElement !== null)
|| document.mozFullScreen
|| document.webkitIsFullScreen;
} function toggleFullScreen(element)
{
if (isFullScreen())
cancelFullScreen();
else
requestFullScreen(element || document.documentElement);
}
通过调用toggleFullScreen函数实现退出全屏。
实现原理为:虽然之前已经F11全屏,但是isFullScreen检测结果依然为false,所以会调用requestFullScreen再次全屏。
而在刚开始实现全屏时会弹出退出全屏话框间接实现退出功能。
 
但是该方法也有个问题即会弹出两次退出全屏对话框,一次是JS调用全屏退出对话框一次是F11调用全屏对话框,如下:
修改toggleFullScreen如下便只弹出一次对话框:
function toggleFullScreen(element)
{
requestFullScreen(element || document.documentElement);
cancelFullScreen();
}

完整代码参考:

<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="../js/jquery-1.10.1.min.js"></script>
<script>
function isFullScreen()
{
return (document.fullScreenElement && document.fullScreenElement !== null)
|| document.mozFullScreen
|| document.webkitIsFullScreen;
} function requestFullScreen(element)
{
if (element.requestFullscreen)
element.requestFullscreen();
else if (element.msRequestFullscreen)
element.msRequestFullscreen();
else if (element.mozRequestFullScreen)
element.mozRequestFullScreen();
else if (element.webkitRequestFullscreen)
element.webkitRequestFullscreen();
} function cancelFullScreen()
{
if (document.exitFullscreen)
document.exitFullscreen();
else if (document.msExitFullscreen)
document.msExitFullscreen();
else if (document.mozCancelFullScreen)
document.mozCancelFullScreen();
else if (document.webkitExitFullscreen)
document.webkitExitFullscreen();
} function toggleFullScreen(element)
{
requestFullScreen(element || document.documentElement);
cancelFullScreen();
} $(document).ready(function(){
$("#exit").click(function(){
toggleFullScreen(document.body);
});
});
</script>
</head>
<body>
<div style="padding-top:300px;"></div>
<button id="exit">退出</button>
</body>
</html>

Chrome退出全屏问题的更多相关文章

  1. js 实现操作浏览器或者元素的全屏与退出全屏功能

    <!DOCTYPE html> <html lang="en" id="div1"> <head> <meta cha ...

  2. js控制全屏及退出全屏

    js控制全屏及退出全屏,网上很多代码例子,我这里需求和标准的有点出入: 1.当用户点击某按钮,触发iframe下的页面全屏. 2.不允许用户退出全屏. 解决第一点,触发全屏可以按照网上的例子,代码如下 ...

  3. HTML5实现全屏API【进入和退出全屏】

    现在主流浏览器基本上实现了全屏效果,但是不同浏览器实现不一样: [进入和退出全屏] // Webkit (works in Safari5.1 and Chrome 15)element.webkit ...

  4. JS控制全屏,监听退出全屏事件

    实现方案 //进入全屏 function requestFullScreen(de) { if(de.requestFullscreen){ //W3C de.requestFullscreen(); ...

  5. js之切换全屏和退出全屏实现

    应用场景:比如很多网页游戏全屏之类的,或者是网上看小说等. 核心代码: //控制全屏 function enterfullscreen() { //进入全屏 $("#fullscreen&q ...

  6. HTML5--浏览器全屏操作、退出全屏、是否全屏

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. iOS 多个播放器同时播放,双击全屏,单击退出全屏

    前言:公司需求如下:点击一个按钮播放一个视频,最多同时播放4个:双击某视频让其全屏,单击再恢复原来的样子.IOS的播放器有两种,MPMoviePlayerController,AVAudioPlaye ...

  8. [delphi]极域学生端解除键盘鼠标锁定退出全屏广播-强制窗口化-源代码

    v2.0  2015-07-11 更新了V2.0 版本 发布在吾爱破解论坛 欢迎下载使用 http://www.52pojie.cn/thread-382769-1-1.html ---------- ...

  9. js控制页面的全屏展示和退出全屏显示

    <!DOCTYPE html> <html> <meta http-equiv="Content-Type" content="text/h ...

随机推荐

  1. AsyncSocket的使用

    AsyncSocket使用流程 安装AsyncSocket 拷贝AsyncSocket类到项目 使用AsyncSocket set delegate @interface NetWork : NSOb ...

  2. HW4.30

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  3. HW4.19

    public class Solution { public static void main(String[] args) { for(int i = 1; i <= 8; i++) { fo ...

  4. std::move()和std::forward()

    std::move(t)负责将t的类型转换为右值引用,这种功能很有用,可以用在swap中,也可以用来解决完美转发. std::move()的源码如下 template<class _Ty> ...

  5. 编译 Spring-framework的经验分享

    Spring-framework source codegit url: git clone git://github.com/SpringSource/spring-framework.git 导入 ...

  6. jQuery 的属性操作方法

    jQuery 属性操作方法 下面列出的这些方法获得或设置元素的 DOM 属性. 这些方法对于 XML 文档和 HTML 文档均是适用的,除了:html(). 方法 描述 addClass() 向匹配的 ...

  7. 转载-Linux下搭建VPN服务器(CentOS、pptp)

    转自:http://www.cnblogs.com/sixiweb/archive/2012/11/20/2778732.html 搭建过程参考这篇文章 先说我搭建过程中出现的问题吧: 按照 教程搭建 ...

  8. Servlet(2)

    一.伪代码演示Tomcat的内部代码运行 1).通过映射找到servlet-class的内容,字符串:com.gqx.servlet.FirstServlet 2).通过反射构造构造FirstServ ...

  9. 使用OpenXML将Excel内容读取到DataTable中

    前言:前面的几篇文章简单的介绍了如何使用OpenXML创建Excel文档.由于在平时的工作中需要经常使用到Excel的读写操作,简单的介绍下使用 OpenXML读取Excel中得数据.当然使用Open ...

  10. ViewPager中使用自定义的ListView实例

    这篇内容是上一篇的延续,因为在上一篇的测试ViewPager成功了,才能实现这一篇的和ListView合在一起使用 效果图如下: 不愿意说理论,直接上代码 1.清单文件 activity_main.x ...