[javascript] 메인 화면에 전체화면 띄우기

async function toggleFullScreenSelectedScreen(){
      if (!document.fullscreenElement) {
            if ('getScreenDetails' in window) {
                  let granted = false;
      
                  try {
                        const { state } = await navigator.permissions.query({ name: 'window-placement' });
                        granted = (state === 'granted');              
      
                        const screenDetails = await window.getScreenDetails();
                        let screensArr = screenDetails.screens;                  
      
                        screensArr.forEach((eachScreen) => {
                              eachScreen.isRecent = (eachScreen.label === screenDetails.currentScreen.label);
                        });
      
                        try {
                              const selectedScreen = screensArr.filter((screen) => screen.isPrimary === true)[0];
      
                              await document.documentElement.requestFullscreen({ screen: selectedScreen });                      
                        } catch (err) {
                              console.error(err.name, err.message);
                        }
                  } catch {
                        console.error(err.name, err.message);
                  }
            }else{
                  document.documentElement.requestFullscreen();
            }
      } else {
            document.exitFullscreen();
      }      
}

Leave a Comment