在 JavaScript 中,當瀏覽器視窗調整大小時發生的事件是什麼?


在 JavaScript 中使用 window.outerWidthwindow.outerHeight 事件以在瀏覽器調整大小時獲取視窗大小。

示例

你可以嘗試執行以下程式碼以處理事件以檢查瀏覽器視窗大小 −

<!DOCTYPE html>
<html>
   <head>
      <script>
         function resizeFunction() {
            var val = "Window Width=" + window.outerWidth + ", Window Height="
            + window.outerHeight;
            document.getElementById("test").innerHTML = val;
         }
      </script>
   </head>
   <body onresize = "resizeFunction()">
      <p>Resize browser window and check the window (browser window)
      height and width again.</p>
      <p id = "test"> </p>
   </body>
</html>

更新於: 2020年6月23日

99 次瀏覽

開啟你的 職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.