JavaScript onresize Event

You are Here:

JavaScript onresize Event

The onresize event occurs when the browser window has been resized.

onresize Event as Attribute

Example

HTML Online Editor
<!DOCTYPE html> <html> <body onresize="myFunction()"> <p>Window resized <span id="point">0</span> times</p> <script> var i = 0; function myFunction() { i += 1; document.getElementById("point").innerHTML = i; } </script> </body> </html>

Syntax

As Attribute

<element onresize = "JavaScript">

As Property

object.onresize = function(){ // code };

Using Event Listener

object.addEventListener("resize" , myScript);

onresize Event as Property

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Try to resize this output window.</p> <p>Window resized <span id="point">0</span> times</p> <script> var i = 0; function myFunction() { i += 1; document.getElementById("point").innerHTML = i; } window.onresize = myFunction; </script> </body> </html>

Using addEventListener() Method

Note: The addEventListener() method is not supported in Internet Explorer 8 and below.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Try to resize this output window.</p> <p>Window resized <span id="point">0</span> times</p> <script> var i = 0; function myFunction() { i += 1; document.getElementById("point").innerHTML = i; } window.addEventListener("resize", myFunction); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author