View Full Version : Invalid tag attributes required; is that a problem?
djr33
02-13-2011, 02:20 AM
I'm working on a project involving one of the scripts here on DD (the anylink menu) and it requires the rel attribute.
The doctype for the site is XHTML strict, and this can't be avoided because I'm integrating it with a forum that uses this. The script works fine.
There are other similar cases where attributes aren't valid but they work. One that comes to mind is target.
For these extra features on a page (opening a link in a new window, applying a Javascript action to a tag, etc.) there is no harm if it doesn't work, since these don't even necessarily need a fallback. They're extra fancy things anyway.
So my question is what to do about the fact that the page won't validate due to "unknown" attributes. Of course the browsers appear entirely happy about it.
Another way to ask the question is this: is it safe to just ignore the validator as long as I understand that nonstandard attributes may not always work, since they're for extra features anyway?
Is the page being served with a mime type of "application/xhtml+xml" (e.g., via server configuration or php header() call; the <meta> tag doesn't cut it )?
If not, then xhtml validation is largely unrelated to how the page will function. The browser is treating it as error-corrected html anyway.
Of course, if it is being served correctly, then IE <9 won't show it at all, but offer a file download dialog.
...
I wouldn't worry about it. It should work fine.
djr33
02-13-2011, 04:53 AM
I'm not doing anything special with it, so I suppose it isn't being served with that mime type.
Here's the shared top throughout the site:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
PHP is not setting a header, but this also matches what the forum does.
As long as it works, that's fine with me.
This is also a theoretical question, though:
What is the best way to deal with the fact that, for example, many of the scripts on Dynamic Drive are invalid, at least for XHTML strict? I know that I will continue to use them, and that they work. So we should just ignore the validator?
[Nicolas]
02-13-2011, 05:14 AM
So we should just ignore the validator?
I ignore it all the time :D I struggled and struggled trying to get my code right and it never worked. I ignore it, do I believe you could and/or should too :)
I think xhtml should be actively discouraged, for the simple reason that most (meaning almost all) " xhtml " pages are actually being served with the html mime-type, and therefore, not being rendered as xhtml anyway. HTML is better at being HTML than xml is. Additionally, HTML5 has the generic data-{whatever} attribute for the express purpose of passing data to scripts - ideal!
Realistically, though, I don't see any easy way around your theoretical problem. All of the scripts would need to be rewritten to make use of valid attributes (e.g., using a class name instead of the rel).
djr33
02-13-2011, 06:05 PM
That makes sense. At the moment I'm just working with what I have, so there's no easy to way to make everything work well as HTML5 and class attributes, for example. But perhaps in 5 years most code will have adjusted itself to be standardized.
lol, you know how many sites I run across that still use HTML3? well, at least I haven't seen a HTML2 site lately.
as far as "working with what you have" goes, completely understandable. It's how the world works
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.