JavaScript

How to detect when a window is resized using JavaScript

You can simply use JavaScript’s window.onresize property to listen for the browser window resize event.

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

How to detect when a window is resized using JavaScript
<!DOCTYPE html>
<html>
	<body>
	<script>
		function handle(evnt){
		  alert("Resize event was triggered." );
		  return true;
		}

		window.onresize = handle;
	</script>

	<p>Drag the browser border to trigger the resize event</p>
	</body>
</html>
Result

Drag the browser border to trigger the resize event

[st_adsense] mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *