--- title: window.onresize slug: Web/API/GlobalEventHandlers/onresize translation_of: Web/API/GlobalEventHandlers/onresize ---
{{ ApiRef() }}
onresize
属性可以用来获取或设置当前窗口的resize事件的事件处理函数
window.onresize = funcRef;
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" } ) }}