Jump to content

Attributes And Elements Of Standards


islandgirl

Recommended Posts

Hello,I am working with a CSS template that has been created to the XHTML strict standards:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">I made some additions to the HTML, for example adding the target="_blank" attribute. When I validate, this line comes up as an error because this particular attribute is not "XHTML strict," instead it's "HTML transitional."What is the best way to handle this? Should I downgrade all the pages on the site? Can I downgrade JUST this one page? Is there anyway to change up this code to make it fit into the "strict" category? How does it really affect things if I were to downgrade the entire site to HTML?Thanks in advance!

Link to comment
Share on other sites

Remove the target attribute, and add a rel attribute that would somehow suggest that the link would open in a new window. Then, with JavaScript, find all links with this rel attribute, and add the target="_blank" attribute to them.Here's JavaScript code that will find links with rel="external", and add target="_blank" to them:

window.onload = function() {	if (!document.getElementsByTagName) {return;}	var anchors = document.getElementsByTagName('a');	for (var i=0; i<anchors.length; i++) {		var anchor = anchors[i];		if (!anchor.getAttribute) {return;}		if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external') {			anchor.target = '_blank';		}	}};

Link to comment
Share on other sites

Guest FirefoxRocks

To answer your other questions, yes you can downgrade this 1 page to Transitional, however I would recommend taking the advice of boen_robot instead.Another thing would be to downgrade from XHTML 1.0 Strict to HTML 4.01 Strict.

1. The language for an element should be specified with a lang attribute rather than the XHTML xml:lang attribute. XHTML uses XML's built in language-defining functionality attribute. 2. Remove the XML namespace (xmlns=URI). HTML has no facilities for namespaces. 3. Change the document type declaration from XHTML 1.0 to HTML 4.01. (see DTD section for further explanation). 4. If present, remove the XML declaration. (Typically this is: <?xml version="1.0" encoding="utf-8"?>). 5. Ensure that the document’s MIME type is set to text/html. For both HTML and XHTML, this comes from the HTTP Content-Type header sent by the server. 6. Change the XML empty-element syntax to an HTML style empty element (<br/> to <br>).
I'm not saying you can't use XHTML but there is a lot of criticism around it and I would recommend HTML4.01 or HTML 5 for now.
Link to comment
Share on other sites

say you had a site that was coded, DTD'ed, and validated to XHTML Strict, would it still validate in HTML Strict without coming up with any errors? (saying if the only thing you did was change the DTD) For example, everything in XHTML must have a closing tag, or self close, would those tags become errors in HTML strict?edit: so I tried it out, and it gave me errors for (which I know are required for XHTML strict validation):<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>and then my only warnings were for self closed tags. Would it be bad to leave those self-closed tags in and let them show up as warnings, or should I just go for removing all the '/'s? I know there is a specific reason for using XHTML, but I like the way it forces you to code cleaner and leaner, but if its for the wrong reasons, I'd rather be in the habit of practicing good web building habits and not putting form over function.

Link to comment
Share on other sites

say you had a site that was coded, DTD'ed, and validated to XHTML Strict, would it still validate in HTML Strict without coming up with any errors? (saying if the only thing you did was change the DTD) For example, everything in XHTML must have a closing tag, or self close, would those tags become errors in HTML strict?
Self closing tags, such as <img />, <link /> and <meta /> are't valid HTML, you need to omit the /.It's actually better if you use XHTML Transitional than trying to get alternatives to the target attribute in XHTML Strict. The XHTML Strict specification doesn't allow the target attribute because the user is supposed to choose whether they want the link to open in a new window or not (by right-clicking and selecting it in the context menu). By adding the attribute with Javascript you're just fooling the validator.
Another thing would be to downgrade from XHTML 1.0 Strict to HTML 4.01 Strict.I'm not saying you can't use XHTML but there is a lot of criticism around it and I would recommend HTML4.01 or HTML 5 for now.
The difference between XHTML Strict and HTML 4.01 Strict is none, so it doesn't matter which on you use. I don't recommend trying to use HTML 5 because it's still a working draft and hardly has any support.
Link to comment
Share on other sites

The XHTML Strict specification doesn't allow the target attribute because the user is supposed to choose whether they want the link to open in a new window or not (by right-clicking and selecting it in the context menu). By adding the attribute with Javascript you're just fooling the validator.
I'm not sure that was the WG's rationale. The real purpose of the "target" attribute is to specify a frame in which the link should open. Since XHTML Strict is about ditching the past, from which frames are part of, they had to remove the "target" attribute to discourage its use on sites running in frames. The fact that they disallowed opening links in new windows is just a side effect. That "users should choose whether or not to open a link in a new window" argument probably appeared later, after the fact, and BTW, if you ask me, that argument is just as valid as "users should choose their default browser". If they care, they should be able to (and browsers do provide the right click as far as the link opening is concerned). If they don't, others should decide for them*. Having said that, not all browsers provide an explicit option to open a link in the same window, which means that if users wanted the link in the same window, they may not always have it easily... but that's perhaps a browser issue.*The same argument is often used in countries where the voters' activity on elections is low. They often say "If you don't vote, you let others vote for you.". I know for a fact that is was used here (in Bulgaria), and in two or three other european countries (can't remember which ones though... Germany and France perhaps?).
Link to comment
Share on other sites

Hi. Can you tell me .. the W3schools webpages are XHTML transitional yes? But there are still examples of the align attribute being used in tables. Are there exceptions to the rule?<br />

<tr><td align="center">

I thought all formatting was to be done with CSS?Ali

Link to comment
Share on other sites

Hi. Can you tell me .. the W3schools webpages are XHTML transitional yes? But there are still examples of the align attribute being used in tables. Are there exceptions to the rule?<br />
<tr><td align="center">

I thought all formatting was to be done with CSS?Ali

In Strict, yes, but not in Transitional. It's called "Transitional" exactly because the idea is for people to "Transition" from using presentational attributes to using CSS.The W3Schools examples may contain them, as the idea is to show (X)HTML, and it's hard to teach something when people can't "see" it. That's why best practices like that are left for the end of the tutorials.
Link to comment
Share on other sites

The W3Schools examples may contain them, as the idea is to show (X)HTML, and it's hard to teach something when people can't "see" it. That's why best practices like that are left for the end of the tutorials.
It was an excerpt of their source code not the front pages.A
Link to comment
Share on other sites

It was an excerpt of their source code not the front pages.A
They're still transitioning I guess.
Link to comment
Share on other sites

I'm really new to this lark , like 2 months or there about, and I think its great .. I think the W3schools site and many other sites are fantastic. Its just a shame that I chose not to get involved with it all 20 years ago. I remember 25 years ago there was Teletext (or Ceefax) editors on the BBC Bs/Acorns. The Open Source philosophy is great to.I think I've done what many new learners have done with tables. Create a table the old way and then try to re-create it using CSS. It can be quite difficult to get an exact match using padding, margins and border-spacing. I had some very strange effects and decided to avoid using padding altogether.The copy was very close to the original and I admit much simpler/less code.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...