Advertisement
laumneto

FS_FRAME

Jul 10th, 2020
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function makeFrame() {
  2.    ifrm = document.createElement("IFRAME");
  3.    ifrm.setAttribute("src", "#");
  4.    ifrm.setAttribute("id", "main_frame");
  5.    ifrm.style.width = '100%';
  6.    ifrm.style.height = '100%';
  7.    ifrm.style.border = 'none';
  8.    ifrm.style.display = 'none';
  9.    document.body.appendChild(ifrm);
  10. }
  11.  
  12. function goFullscreen() {
  13.     const button_FS = localStorage.getItem('FullScreen');
  14.     if(button_FS == 'Inativo' || button_FS == null){
  15.         makeFrame();
  16.         const mf = document.getElementById("main_frame");      
  17.         if ((document.fullScreenElement !== undefined && document.fullScreenElement === null) || (document.msFullscreenElement !== undefined && document.msFullscreenElement === null) || (document.mozFullScreen !== undefined && !document.mozFullScreen) || (document.webkitIsFullScreen !== undefined && !document.webkitIsFullScreen)) {
  18.             if (mf.requestFullScreen) {
  19.                 mf.requestFullScreen();
  20.             } else if (mf.mozRequestFullScreen) {
  21.                 mf.mozRequestFullScreen();
  22.             } else if (mf.webkitRequestFullScreen) {
  23.                 mf.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  24.             } else if (mf.msRequestFullscreen) {
  25.                 mf.msRequestFullscreen();
  26.         }
  27.             mf.style.display="block";
  28.             localStorage.setItem("FullScreen","Ativo");
  29.         }  
  30.     }else if(button_FS == 'Ativo'){
  31.         ////// SÓ FUNCIONA COM O ALERT() AQUI ////////////
  32.         const mf = document.getElementById("main_frame");
  33.         //mf.style.display="none";
  34.         var xframe = document.getElementById("main_frame");
  35.         xframe.parentNode.removeChild(xframe);
  36.         localStorage.setItem("FullScreen","Inativo");      
  37.     }  
  38. }
  39.  
  40. function fullscreenChanged() {
  41.     if (document.webkitFullscreenElement == null) {
  42.         const mf = document.getElementById("main_frame");
  43.         mf.style.display="none";
  44.         var xframe = document.getElementById("main_frame");
  45.         xframe.parentNode.removeChild(xframe);
  46.         localStorage.setItem("FullScreen","Inativo");      
  47.     }
  48. }
  49.  
  50. document.onwebkitfullscreenchange = fullscreenChanged;
  51.    
  52. $(document).ready(function(){
  53.     $('#btn_FS').on('click', function(){
  54.         goFullscreen();
  55.     });
  56. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement