/    Sign up×
Community /Pin to ProfileBookmark

Can I ask a DOM questions?

The DOM is not always fully loaded when the onload event occurs! That is why I want to change this to an onresize event. By then the page width should be in the DOM.

But, I’m confused!

I’ve read in a few places that onresize is not actually supported as part of the body tag even though most browsers do allow it. On the w3c site, on the DOM Body page is only shows onload as a legal body event, but it also states that “The body object also supports the standard properties, methods, and events.” One of which is onresize.

The window object does not even mention onresize.

When working with Komodo and TopStyle, onresize does not appear as a legal attribute of body.

The code that I have written is kicked off by <body onload=…>. On some pages this works fine, on other pages it fails to realize the correct page width because the page has not finished displaying and the DOM is not updated. My code also tests for window.onresize == null and then sets it to call the same script as body onload. That causes the script to re-run when the DOM is updated and all is OK.

So, why does onresize work as a window attribute when it isn’t even mentioned?

Is it truly supported by the body tag, then why doesn’t an editor like Komodo reference it?

Not following the specs might make it work on some browsers and not on others!

I love standards — there are so many to choose from !

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangAug 25.2010 — The W3C specs are only recommendations. Browser can and do depart from the specs.

http://www.quirksmode.org/dom/events/resize.html

Don't put JavaScript in the html:[CODE]<body onload=...>[/CODE]
Try to keep all script separate[CODE]<script type="text/javascript">
window.onload=function() {
alert('onload');
};
</script>
[/CODE]
×

Success!

Help @PapaGeek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...