1

I am trying to get fullscreen mode using javscript. So I found this answer and working on it. But I found out that, when I am triggering full screen using this code scrollbar disappears and scroll is disabled. But if I am using F11 to trigger the same, scrollbar appears and scroll is possible. I had tried to give overflow:auto to body but it does'nt have anyy effect. Here is the fiddle that reproduces the same issue. When you run the fiddle you will be able to see that all paragraphs are not visible.

Note: I am using Firefox 45.

HTML :

<body>
      <input type="button" value="click to go fullscreen" onclick="requestFullScreen()">
      <p>
       1 some text to make screnn bigger
      </p>
        <p>
         2some text to make screnn bigger
      </p>
        <p>
       3 some text to make screnn bigger
      </p>
        <p>
        4some text to make screnn bigger
      </p>
        <p>
        5some text to make screnn bigger
      </p>
        <p>
       6 some text to make screnn bigger
      </p>
        <p>
        7some text to make screnn bigger
      </p>  <p>
       8 some text to make screnn bigger
      </p>
        <p>
       9 some text to make screnn bigger
      </p>
        <p>
       10 some text to make screnn bigger
      </p>
        <p>
       11some text to make screnn bigger
      </p>
        <p>
        12 some text to make screnn bigger
      </p>
        <p>
        13 some text to make screnn bigger
      </p>
        <p>
       14 some text to make screnn bigger
      </p>
        <p>
       15 some text to make screnn bigger
      </p>
        <p>
        16 some text to make screnn bigger
      </p>
    </body>

Javascript:

function requestFullScreen() {

  var el = document.body;

  // Supports most browsers and their versions.
  var requestMethod = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen;

  if (requestMethod) {

    // Native full screen.
    requestMethod.call(el);

  } else if (typeof window.ActiveXObject !== "undefined") {

    // Older IE.
    var wscript = new ActiveXObject("WScript.Shell");

    if (wscript !== null) {
      wscript.SendKeys("{F11}");
    }
  }
}
Nagaraju
  • 1,853
  • 2
  • 27
  • 46

1 Answers1

4

Change el to document.documentElement and the scrolling will work in Firefox.

var el = document.documentElement;

It will break in JSFiddle while using Chrome(because of iframe policies I guess), but I don't think that's the main use.

yuriy636
  • 11,171
  • 5
  • 37
  • 42