--- title: window.onresize slug: Web/API/GlobalEventHandlers/onresize tags: - DOM - Gecko - Property - Window translation_of: Web/API/GlobalEventHandlers/onresize original_slug: Web/API/Window/onresize ---
{{ ApiRef() }}
GlobalEventHandlers.onresize プロパティは、{{event("resize")}} イベントを受信するとトリガーされる {{event("Event_handlers", "event handler")}} を含みます。
window.onresize = funcRef;
funcRef: 関数への参照window.onresize = doFunc;
<html>
<head>
<title>onresize test</title>
</head>
<body>
<p>Resize the browser window to fire the resize event.</p>
<p>Window height: <span id="height"></span></p>
<p>Window width: <span id="width"></span></p>
<script type="text/javascript">
var heightOutput = document.querySelector('#height');
var widthOutput = document.querySelector('#width');
function resize() {
heightOutput.textContent = window.innerHeight;
widthOutput.textContent = window.innerWidth;
}
window.onresize = resize;
</script>
</body>
</html>
ブラウザウィンドウのサイズが変更された後に resize イベントが発生します。
| 使用 | ステータス | コメント |
|---|---|---|
| {{SpecName('HTML WHATWG','webappapis.html#handler-onresize','onresize')}} | {{Spec2('HTML WHATWG')}} |