How to get height and width after window resize

后端 未结 3 2007
南方客
南方客 2021-01-14 13:10

I have a scorm module which launches in a new window with resizable = 1 in window.open in my js file:

function OpenScormModuleWindow(scormModuleId, scormModu         


        
3条回答
  •  再見小時候
    2021-01-14 13:38

    Use an event listener which listens on resize, then you can reset your values:

    window.addEventListener('resize', setWindowSize);
    
    function setWindowSize() {
      if (typeof (window.innerWidth) == 'number') {
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
      } else {
        if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
          myWidth = document.documentElement.clientWidth;
          myHeight = document.documentElement.clientHeight;
        } else {
          if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
            myWidth = document.body.clientWidth;
            myHeight = document.body.clientHeight;
          }
        }
      }
    }
    

    If you need a cross browser solution use jQuery ($.on('resize', func)) or see JavaScript window resize event

提交回复
热议问题