--- title: window.onresize slug: Web/API/GlobalEventHandlers/onresize translation_of: Web/API/GlobalEventHandlers/onresize ---

{{ ApiRef() }}

概述

onresize属性可以用来获取或设置当前窗口的resize事件的事件处理函数

语法

window.onresize = funcRef;

参数

例子

window.onresize = doFunc;
<html>
<head>

<title>onresize测试</title>

<script type="text/javascript">

window.onresize = resize;

function resize()
{
 alert("检测到resize事件!");
}
</script>
</head>

<body>
<p>改变浏览器窗口的大小来触发resize事件.</p>
</body>
</html>

备注

在窗口大小改变之后,就会触发resize事件.

规范

Specification Status Comment
{{SpecName('HTML WHATWG','webappapis.html#handler-onresize','onresize')}} {{Spec2('HTML WHATWG')}}  

{{ languages( {"en": "en/DOM/window.onresize" } ) }}