javascript - msRequestFullscreen 在 keydown 事件(IE 11)的情况下不起作用
问题描述
我正在使用全屏 api。
我已经添加了这个 polyfill:
let doc = document as any;
if (!doc.requestFullscreen) {
document.body.requestFullscreen = doc.body.mozRequestFullScreen ||
doc.body.webkitRequestFullscreen || doc.body.msRequestFullscreen;
document.exitFullscreen = doc.mozCancelFullScreen || doc.webkitExitFullscreen ||
doc.msExitFullscreen;
}
我有用于启用全屏模式的 UI 按钮,并且一切正常(chrome IE 11、edge、opera、firefox)
我也有 keydown 处理程序:
if (args.keyCode === 70) {
args.preventDefault();
if (!this.isInFullScreen) {
document.body.requestFullscreen();
}
else {
document.exitFullscreen();
}
this.InFullScreen = !this.isInFullScreen;
}
但是通过按 F 启用/禁用全屏模式在 IE 11中不起作用。
msRequestFullscreen 函数根本不执行任何操作。没有控制台错误或smth。在其他浏览器中工作正常。
我该如何解决这个问题?
解决方案
我可以重现这个问题。在 IE 11 中工作,但它在事件msRequestFullscreen
中不起作用。keyCode
作为一种解决方法,我建议您可以使用ActiveXObject
F11 SendKeys
。它可以在 IE 11 中使其全屏显示。您可以添加以下代码:
if ("ActiveXObject" in window) {
var wscript = new ActiveXObject("Wscript.shell");
wscript.SendKeys("{F11}");
}
推荐阅读
- gdb - vscode+Qemu+TinyOS 无法使用 GUI gdb
- c# - 如何限制用户登录我的应用程序
- r - 使用 R 语言中的 normalmixEM2comp 在每次迭代后更新高斯混合模型的参数
- c++ - 如何将小端格式的 QByteArray 转换为无符号长
- c# - 如何解析 Nethereum 中的签名交易?
- java - Orika:java.lang.ClassCastException:java.lang.Object 无法转换为 mapper.Name
- laravel - 公用文件夹的 Laravel 子文件夹问题
- botframework - 如何将 Bot 框架与 SQL Server 分析服务或 Azure 分析服务等分析服务连接起来?
- python - 如何在多个文件中搜索 3 个单独的字符串并将它们打印到 python 中的 excel 文件中?
- css - 最小主题中的自定义 CSS