onresize event


onresize Event

Instance

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
function myFunction(){
	var w=window.outerWidth;
	var h=window.outerHeight;
	var txt="窗口大小: 宽度=" + w + ", 高度=" + h;
	document.getElementById("demo").innerHTML=txt;
}
</script>
</head>

<body onresize="myFunction()">
<p>尝试调整浏览器的窗口</p>
<p id="demo"> </p>
<p>注意:该例子在IE8 或更早版本下可能不工作,IE8 或更早的版本不支持window对象的outerWidth/outerHeight属性</p>

</body>
</html>

Run Instance»

Click "Run instance" button to view the online instance


Definition and usage

The onresize event occurs when the window or frame is resized.

Syntax

In HTML:

<elementonresize="SomeJavaScriptCode">

JavaScript:

window.onresize=function(){SomeJavaScriptCode};

##ParametersDescriptionRequired. Specifies the JavaScript to be executed when this event occurs.
SomeJavaScriptCode


Browser Support

QQ截图20161108165429.png##All major browsers support the onresize event

The following HTMl tags support onresize events:

<a>, <address>, <b>, <big>, <blockquote>, <body>, <button>, <cite>, <code>, <dd>, <dfn>, <div>, <dl>, <dt>, <em>, <fieldset>, <form>, <frame>, <h1> to <h6>, <hr>, <i>, <img>, <input>, <kbd>, <label>, <legend>, <li>, <object>, <ol>, <p>, <pre>, <samp>, <select>, <small>, <span>, <strong>, <sub>, <sup>, <table>, <textarea>, <tt>, <ul>, <var>