How to set <body> onresize event from Javascript code?

For some reason, I need to use Javascript to set the onresize event of the body tag on my web page. I tried to use this:

document.body.setAttribute("onresize", "alert('aaa');");

But it doesn't work. Does anybody know how to use Javascript to set onresize event of body tag?

Thanks a lot.
LVL 1
BruceChengAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

archrajanCommented:
<body onresize = "alert('Resized')">
0
archrajanCommented:
sorry that will nto work
0
archrajanCommented:
<body  onResize="alert('HI')"">  this works
0
BruceChengAuthor Commented:
I mean I need to set this "onresize" event javascript from Javascript code.

That <body> tag is from a global include file of my application. I cannot change the <body> tag at all.

Thanks.
0
GwynforWebCommented:
the body of the page you are trying to cahnge must be loaded before you can set the onresize.

<body>
   <script>document.body.onresize=function(){alert('hello')}</script>
</body>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.