firefox Browser rejected fullscreen change

后端 未结 1 1956
离开以前
离开以前 2021-02-15 14:38

I\'m trying to make a element of my website in fullscreen when we click on it, and it works with chrome, IE, but not with firefox.

I went to the microsoft fullscreen API

1条回答
  •  鱼传尺愫
    2021-02-15 15:27

    This code segment should work for most browsers incl. Mozilla Firefox. Specifically, Mozilla Firefox insists that the code in the event handler executes under 1 second. Else Fullscreen requests are denied. Refer: Bug Report

    HTML

    
    

    Javascript

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

    Refer to the FullScreen API for more details Fullscreen API

    The above code segment's working Demo: Fullscreen Demo

    0 讨论(0)
提交回复
热议问题