PDA

View Full Version : xhtml, w3c validation, and javascript



marain
07-28-2012, 04:49 PM
Is there any point in attempting to alter javascript scripts, using escape characters and the like, in order to obtain a clean xhtml w3c validation? Are such clean validations even possible?

A.

jscheuer1
07-28-2012, 06:27 PM
That's really two separate questions. The first is pretty much a matter of opinion.

Generally XHTML isn't being used correctly anyway. It's for application XML pages, which some browsers still in wide use (most notably IE 8) can't process anyway. Usually it's just served as HTML and error corrected by the browser as HTML 4.01.

That said, you can validate javascript to an XHTML DOCTYPE fairly easily in one of two ways, don't do both, though it won't hurt, it's just extra work:


Make the script external. The validator won't even see it. This is the preferred method.


Use not character data comment delimeters at the beginning and end of the on page script code:


<script type="text/javascript">
/* <![CDATA[ */
Your script code goes here
/* ]]> */
</script>

This method should only be used when making the script external is impossible or impractical for some reason. It tells the validator not to consider the delimited code as XHTML.


Using escapes is never required for validation under the XHTML DOCTYPE. Escapes can be required for proper function of a script, though usually much less so than many people imagine.

They are often required in many places in HTML 4.01 for on page script code to validate, and sometimes are not enough for that purpose. The not character data delimiters don't help there. The HTML comment delimiters might, but they carry their own risks. Best to make the scripts external rather than to resort to those.

With HTML 5 you can do anything you can do with XHTML, and anything you can do with HTML 4.01, and of course more than both combined. And script code is ignored by the HTML 5 validator. So there's no problem there. But there are other validation requirements in HTML 5 that are absent in both XHTML and HTML 4.01. So sometimes you are left either choosing the best DOCTYPE to work with for validation purposes, or just not worrying about validation.

I like my code to validate, especially example and professional production code. But if there doesn't appear to be any reasonable path to validation in such circumstances, I will let it slide as long as I'm confident it won't cause a problem. When I'm helping someone else I don't worry about it unless their existing code is already 100% valid, or if validation is their goal.

Validation is pretty much best used to diagnose and avoid problems. It can be taken to extremes. But just about everyone, once they start validating their own pages, would much rather see that green bar rather than the red one.

One thing to bear in mind is that there are a number of invalid CSS errors on the validator pages. I think I even validated a few of them once and they had HTML validation errors. So that shows what they think of their own standards. They're guidelines, not the law.

bernie1227
07-29-2012, 01:50 AM
In my opinion, the W3C validation guidelines are really just reinforcements of good coding practices. If you have good coding practices (i.e. lowecase html tags, ending tags, etc.) then you can pass validation, the guidelines are really to help webpaes to become more easily understandable, as well as helping compatability, which may be effected by the forementioned examples. The W3C guidelines are there to make the web a better place, and if you simply ignore them, then your webpage can quickly detereorate into an unreadable mess.

They also help when you want to go back an edit a page later, or if suddenly you webpage has stopped woring. If you have followed the W3C guidelines, you should be able to both easily read and understand your own code, and be able to pass it through the validator and see if their are any problems with the code that may be effecting it. As per John said they are not laws and you don't have to follow them, but it well help both you and the greater web community greatly.

In summary, there is most definately a point in at least attempting to validate your pages.

@John - Some of thir pages may be invalid but that doesn't mean that you shouldn't follow them anyway, as far as I know, extraordinarily few of the W3C affliates, ie, Google, Bing, have valid webpaes, but once again, that dosn't mean that you shouldn't follow them. In this case, it may look like do what I say, not What I do, but the W3C guidelines are usefull and should be followed.

djr33
07-29-2012, 04:32 AM
Check your pages and investigate the errors. If you find an error that is not really a problem (a great example is something in Javascript, or something that is non-standard but intentional) then you can in almost all cases ignore it. Just do this thoughtfully and stick to standards unless you have a good reason to ignore them.

marain
07-29-2012, 06:19 PM
Well then the remaining concern is for those who want to use the w3c icon. It wouldn't do to include the icon on a page that doesn't validate. (Or is the icon just vanity in the first place?)

jscheuer1
07-29-2012, 07:25 PM
Vanity and/or insanity. It's generally not all that hard to get your page to validate, though it sometimes can be quite a chore. It often does require some general knowledge about HTML and CSS or a WYSIWYG editor that writes valid code. As far as javascript goes, that should never be a problem. Just make the script external, or use an HTML 5 DOCTYPE, or an XHTML DOCTYPE with not character data comments around the script code.

bernie1227
07-29-2012, 09:52 PM
In my experience, the valid icons are really just vanity, so the designers of the webpage going, "hey! Look at me, I can write valid code!", it is certainly likely, though not ethical, that some web designers do put valid buttons on their webpage when it isn't valid, I have come across that numerous times. Personally, I write my code to XHTML 1.0 strict standards, but I don't like to include the valid button, because often it just isn't in the feel of the webpage I'm making.

marain
07-29-2012, 10:15 PM
I think there's another valid way of looking at it. w3c validation performs an often valuable service. When a web page doesn't work as intended, w3c validation can often help determine why. Use of the icon is a way of publicizing the w3c. This serves a useful educational purpose.

bernie1227
07-29-2012, 10:33 PM
That may be true, however, think about how much exposure this would actually get them, if so few webpages are even valid, let alone have the button on it.

jscheuer1
07-30-2012, 12:27 AM
I agree that there is some vanity and/or sense of accomplishment in validating a page. And that the icons often look out of place on a professional page. They do go well on a demo page if you're trying to emphasize that your code can be used on a valid page.

And I agree that the validation service is an invaluable tool when something is awry with your page. It won't always solve it, but it often can, especially when you've exhausted all other avenues available.

I'm not sure the w3c needs any publicity via those icons though. Perhaps. But I'm sure they realize that virtually all serious developers would never display them on commercial work.

I think they have all the notoriety they need simply by virtue of the fact that if you do any serious search on elements, syntax, objects, etc. involved in HTML, XHTML, JavaScript, XML, CSS - just to name the main ones, you are bound to run across the w3c a lot.

marain
07-30-2012, 01:27 PM
Well let me say first of all that my aesthetic sensitivities are, admittedly lacking. What I do with my sites may, therefore, be heavily influenced by this dialogue. In that vein, I pose another thought. Should w3c be treated differently than, let us say, Dynamic Drive icons. Look at the footer of www.marainlaw.com. The icons for both (as well as some others) are there. Do they look out of place? Is it inappropriate for commercial sites to publicize Dynamic Drive, the volunteers of which are helpful to me and to so many others? If not, how would w3c be different?

BTW, getting back to the issue that prompted my original question, I did move the script to a linked file as suggested, and the page (http://www.marainlaw.com/page.php?here=quotations) now validates. Thank you!

A.

jscheuer1
07-30-2012, 03:36 PM
I'm not much of a designer either, but on those pages, those logos don't look out of place.

You do have one CSS validation error though, in an on page stylesheet:


. . . me="revisit-after" content="5 days" />
<meta name="distribution" content="Global" />

<link rel="stylesheet" type="text/css" href="css/marainlaw.css" />

<style type="text/css">
.intro{
position:absolute;
left:0;
top:0;
layer-background-color:#ffff00;

/* #ffff00 = yellow */

background-color:black;
border:8.0px solid blue;
z-index:10;
}
</style>
<script language="JavaScript" type="text/javascript" src="js/popwin.js"></script>

</head> . . .

I couldn't find any element on the page with the "intro" class though, so you should be able to just get rid of it. See:

http://www.blooberry.com/indexdot/css/properties/colorbg/lbgcolor.htm

for more info on layer-background-color, which it appears from that should be dropped and the background-color should be set to the preferred color, which in this case appears to be #ffff00;

Netscape, at least the versions they're talking about there (4.0, 4.x) are no longer in use. And I know for almost an absolute fact that current Netscape, and for absolute fact it's step children (Mozilla, including Firefox), no longer require this hack.

marain
07-30-2012, 07:25 PM
I think I need to look at it more closely before deleting it. php puts some code into the header, so it does appear to be in use:

[CODE]

<?php
.
.
.

if ( $here === 'quotations' ) {
echo '<style type="text/css">
.intro{
position:absolute;
left:0;
top:0;
layer-background-color:#ffff00;

/* #ffff00 = yellow */

background-color:black;
border:8.0px solid blue;
z-index:10;
}
</style>';
}

?>

[CODE]

So it will be either delete or correct (if it's correctable), but I'll very likely not have a chance to study that today.

A.