onresize and validation

Posted on 2011-10-31
Last Modified: 2012-05-12
While using HTML 4.01 Transitional, I add the onresize event handler to the <body> tag. This does the job in all browsers. However, EW marks the attribute as "not permitted".
        1. Does this mean "not permitted for validation"? (Attribute is obviously permitted by browsers, as it performs OK.)
EW actually states "not permitted for the <body> tag".
        2. Is onresize permitted for other tags? (Doesn't validation require all handlers be removed from HTML?)
I wonder what is a reason for this validation requirement, as it looks a lot more difficult to read / edit / fix code when handlers do not show as element attributes in HTML, but instead are hidden in .js files. I understand separation of HTML code and script, but isn't this too much of that?
Question by:campinam
    LVL 53

    Accepted Solution

    Standards are developed by a committee that includes the browser manufacturers. When a non-approach is "allowed" by a browser it is generally for backward compatibility.  If you continue to use such methods you run the risk that a browser will discontinue it and break your pages, or that newer browsers will be more strict and not support your pages.

    As to "hiding" events in script.  That is not the case. The body does not have a re-size method.  On the document and window there is a re-size method.  The body can only be re-sized in response to a re-sizing of the document or window; or through scripting to modify its style properties.  The re-size in the body tag is semantically incorrect, and needed to be removed to maintain the integrity of the DOM.

    LVL 81

    Expert Comment


    Author Comment

    Thank you much.
    But why are handlers like onselectstart or ondragstart not allowed on <div>, for instance?
    Actually, should ALL handlers be removed from HTML in order for the page to validate?
    LVL 53

    Expert Comment

    HTML5!  You are validating with HTML4.01 and ondragstart is valid in HTML5.  There is an onselect but not onselectstart which logically would not make sense anyway. You don't need a start and stop event for selection.

    Browsers will sometimes support thing ahead of the standard release, and sometimes they play catch up and support something long after the release.

    There is no law that says you have to validate, or that you can't use proprietary code, but a prudent professional generally follows standards so they can make a living developing new projects instead of hacking out patches to get around incompatibilities.

    As for any WHY when it comes to standards; it is always the same answer.  Standards are the compromise that competing interest could agree to.

    Author Comment

    I appreciate your insight.
    Hopefully, browsers won't cancel support for old pages for the next 20 years... (?)
    LVL 53

    Expert Comment

    If they do there will be a lot of broken sites; but it won't be the first time that developers have had to retrofit.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Adobe Dreamweaver CC 2015

    Adobe Dreamweaver Creative Cloud is used by web designers and front-end developers and allows you to visualize your site in real-time as you code. This course covers exam objectives for the Adobe Certified Associate (ACA) certification.

    Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
    This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now