Computer >> Máy Tính >  >> Lập trình >> Javascript

Sự kiện nào xảy ra khi cửa sổ trình duyệt được thay đổi kích thước trong JavaScript?


Sử dụng window.outerWidth window.outerHeight sự kiện trong JavaScript để lấy kích thước của cửa sổ khi trình duyệt được thay đổi kích thước.

Ví dụ

Bạn có thể thử chạy mã sau để làm việc với các sự kiện nhằm kiểm tra kích thước cửa sổ trình duyệt -

<!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>