简体   繁体   中英

How to make page fullscreen on load or when I want

I am using the DataTables plugin for my project and it's not working correctly. I found way to fix it but I need help.

When I resize my page using windows tools or when I open the console page it's changing the size and it's working correctly.

I tried this function and it's working correctly :

function toggleFullScreen(elem) {
  if ((document.fullScreenElement !== undefined && document.fullScreenElement === null) || (document.msFullscreenElement !== undefined && document.msFullscreenElement === null) || (document.mozFullScreen !== undefined && !document.mozFullScreen) || (document.webkitIsFullScreen !== undefined && !document.webkitIsFullScreen)) {
    if (elem.requestFullScreen) {
      elem.requestFullScreen();
    } else if (elem.mozRequestFullScreen) {
      elem.mozRequestFullScreen();
    } else if (elem.webkitRequestFullScreen) {
      elem.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
    } else if (elem.msRequestFullscreen) {
      elem.msRequestFullscreen();
    }
  } else {
    if (document.cancelFullScreen) {
      document.cancelFullScreen();
    } else if (document.mozCancelFullScreen) {
      document.mozCancelFullScreen();
    } else if (document.webkitCancelFullScreen) {
      document.webkitCancelFullScreen();
    } else if (document.msExitFullscreen) {
      document.msExitFullscreen();
    }
  }
}

When I click on this button it's working correctly:

<button onclick="toggleFullScreen(document.body);">Click On Me</button>

However when I use this function like this:

toggleFullScreen(document.body);

It's not working and it's showing this in the console:

mozRequestFullScreen() is deprecated.

Request for fullscreen was denied because Element.requestFullscreen() was not called from inside a short running user-generated event handler.

TypeError: The expression cannot be converted to return the specified type.

use jQuery to click the button instead of calling the function. Bit of a work around but will work for what you need.

jQuery('button').click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM