HTML 5全屏站点在内部链接上退出全屏模式

时间:2012-10-11 13:44:41

标签: html

我正在使用HTML 5构建网站,并希望拥有全屏选项。我使用下面的代码工作,但是当你点击一个内部链接时,它退出全屏模式。这是不可取的。我已经广泛搜索并且没有看到任何关于这个问题的答案,只是关于iOS的webapps的问题,这不是。演示网站位于:http://kvrm.co.uk/jw/

我还注意到,当在Firefox中全屏显示时,屏幕底部会出现一个黑带,这在Chrome或Safari中不会发生。

如何在导航到其他内部网页时将网站保持在全屏模式? (另外,关于Firefox中的黑条可以做些什么吗?)

以下是全屏代码:

(function () {
var viewFullScreen = document.getElementById("view-fullscreen");
if (viewFullScreen) {
    viewFullScreen.addEventListener("click", function () {
        var docElm = document.documentElement;
        if (docElm.requestFullscreen) {
            docElm.requestFullscreen();
        }
        else if (docElm.mozRequestFullScreen) {
            docElm.mozRequestFullScreen();
        }
        else if (docElm.webkitRequestFullScreen) {
            docElm.webkitRequestFullScreen();
        }
    }, false);
}

var cancelFullScreen = document.getElementById("cancel-fullscreen");
if (cancelFullScreen) {
    cancelFullScreen.addEventListener("click", function () {
        if (document.exitFullscreen) {
            document.exitFullscreen();
        }
        else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
        }
        else if (document.webkitCancelFullScreen) {
            document.webkitCancelFullScreen();
        }
    }, false);
}


var fullscreenState = document.getElementById("fullscreen-state");
if (fullscreenState) {
    document.addEventListener("fullscreenchange", function () {
        fullscreenState.innerHTML = (document.fullscreen)? "" : "not ";
    }, false);

    document.addEventListener("mozfullscreenchange", function () {
        fullscreenState.innerHTML = (document.mozFullScreen)? "" : "not ";
    }, false);

    document.addEventListener("webkitfullscreenchange", function () {
        fullscreenState.innerHTML = (document.webkitIsFullScreen)? "" : "not ";
    }, false);
}

var marioVideo = document.getElementById("mario-video")
    videoFullscreen = document.getElementById("video-fullscreen");

if (marioVideo && videoFullscreen) {
    videoFullscreen.addEventListener("click", function (evt) {
        if (marioVideo.requestFullscreen) {
            marioVideo.requestFullscreen();
        }
        else if (marioVideo.mozRequestFullScreen) {
            marioVideo.mozRequestFullScreen();
        }
        else if (marioVideo.webkitRequestFullScreen) {
            marioVideo.webkitRequestFullScreen();
            /*
                *Kept here for reference: keyboard support in full screen
                * marioVideo.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
            */
        }
    }, false);
}

})();

1 个答案:

答案 0 :(得分:0)

使用iframe。外部页面仅包含切换全屏按钮和填充屏幕其余部分并包含真实内容的大型iframe。您的布局在切换按钮左侧已有一个清晰的空间,因此您甚至无需更改布局。

iframe中的导航,甚至是其他域的导航,都不会破坏外框的全屏模式。

您需要小心调整iframe的大小,以便外框上没有滚动条。