如何在 PWA 中以编程方式将显示从独立切换到全屏
问题描述:
当我将清单的显示"设置为全屏"或独立"时,我的 PWA 会按预期工作.但是,我希望我的用户能够在设置中来回切换.有没有办法在 JavaScript 中以编程方式切换?
My PWA works as expected when I set the "display" of my manifest to "fullscreen" or "standalone". But, I want my users to be able to toggle back and forth in settings. Is there a way to switch this programmatically in JavaScript?
答
如果您想确保它适用于所有浏览器,请尝试此操作.
try this if you want to be sure that it will work in all browsers.
function getFullScreen() {
if (document.body.requestFullscreen) {
document.body.requestFullscreen();
} else if (document.body.mozRequestFullScreen) { /* Firefox */
document.body.mozRequestFullScreen();
} else if (document.body.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
document.body.webkitRequestFullscreen();
} else if (document.body.msRequestFullscreen) { /* IE/Edge */
document.body.msRequestFullscreen();
}
}