onresize Event

Event Object Reference Event Object

Example

Execute a JavaScript when the browser window is resized:

<body onresize="myFunction()">

Try it yourself »

More "Try it Yourself" examples below.


Definition and Usage

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

Tip: To get the size of an element, use the clientWidth, clientHeight, innerWidth, innerHeight, outerWidth, outerHeight, offsetWidth and/or offsetHeight properties.


Browser Support

Event
onresize Yes Yes Yes Yes Yes

Syntax

In HTML:

<element onresize="myScript">Try it

In JavaScript:

object.onresize=function(){myScript};Try it

In JavaScript, using the addEventListener() method:

object.addEventListener("resize", myScript);Try it

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


Technical Details

Bubbles: No
Cancelable: No
Event type: UIEvent
Supported HTML tags: <body>
DOM Version: Level 2 Events

Examples

More Examples

Example

Using the addEventListener() method to attach the "resize" event on the window object.

window.addEventListener("resize", myFunction);

Try it yourself »

Event Object Reference Event Object

SHARE THIS PAGE

COLOR PICKER

colorpicker





Search w3schools.com:

Translate w3schools.com: