Handle browser window resize event in JavaScript

Description

The following code shows how to handle browser window resize event.

Example


<!--from  ww w. j  a v a2s . com-->
<html>
<body>
<script language = JavaScript>
function handle(evnt){
alert("A RESIZE event has occurred." );
return true;
}

window.onresize = handle;
</script>
<form name="form1">
Drag the browser border to trigger the resize event

</form>
</body>
</html>

Click to view the demo

The code above generates the following result.

Handle browser window resize event in JavaScript
Home »
  Javascript Tutorial »
    Event »
      Browser Event
Javascript Tutorial Browser Event
Access window event in JavaScript
Add event handler for body onload event in ...
Add event handler for window on load event ...
Add onload event handler by using attribute...
Cancel event with preventDefault in JavaScr...
Filter click event to capture in JavaScript
Filter event to catch in JavaScript
Handle Error event on body in JavaScript
Handle browser window resize event in JavaS...
Handle document on changed event in JavaScr...
Handler document on abort event in JavaScri...