Forum Moderators: open
My question is what DOCTYPE should I use.
If I use transitional I fear that, over time, I will be introducing some of the non-strict constructs that I have removed.
Will any browser have problems dealing with the target=_blank if I claim to be strict compliant?
<BASE href="http://www.mycompany.com" target="mainContent">
To be honest, I'm not sure if there is a replacement for the target="_blank" in HTML4.01.
Why not make your own DTD with the attribute and tags you want added. It's very simple. Just copy the one you start from to a local directory and make the changes, then reference it from your web site. Your validation will now work.
Richard Lowe
[edited by: richlowe at 4:28 pm (utc) on July 3, 2003]
Browers (at least IE) do not use it at all.
I don't think that this is true - the example I would cite is the fact that without a valid DTD, some browsers will go into Quirks Mode and there can be major differences in the way CSS is rendered.
<edit>Typo Fix</edit>
[edited by: BlobFisk at 4:29 pm (utc) on July 3, 2003]
This is an area where the idealism of standards and the pragmatism of real world development collide in a somewhat messy fashion. I see at least four intertwined topics here -- the Doctype itself, validation against that Doctype, browser behaviors, and dealing with the practical issue of opening a document in a new window.
STANDARDS vs. QUIRKS MODE
A modern browser will go into standards mode if there is a valid Doctype (for HTML 4 on up). The browser does not first validate the entire page to be sure - it just uses standards mode.
So, if there is non-valid HTML on the page, it will attempt to execute that code in whatever "error recovery" manner the browser developers included. But the browser won't go into quirks mode just because there is a bit of invalid code.
In this case we're talking about an obsolete attribute, and not malformed tags. Browsers already include in their code instructions for executing target="_blank" and that's what they use. I've tested a few, and none of them go to quirks mode.
So you "can" use the strict DTD, and your reasoning makes sense to me, but just don't put the W3C valid code logo on your page.
OPENING A NEW WINDOW IN STRICT HTML
Now here is the mess. Everything you try has a downside. You can use javascript's window.open() method, but of course you run into problems with disabled/no javascript and some of the sub-par pop-up blockers.
Even when the user agent does execute the javascript, many browsers do not pass on the referrer. In many situations (external links, for example) that is not acceptable.
Sitepoint has an article by Kevin Yank [sitepoint.com] where he explains how Sitepoint approaches the problem. They use the newly introduced attribute rel= and give it a non-standard argument rel="external". Then they run a script on every page to find all the hyperlinks. Whenever a link has the attribute rel="external" the javascript function then declares anchor.target = "_blank"; for that link.
This approach does validate and it also avoids the referrer problem, so it has those advantages. Older browsers, however, will just open the link in the same window. Not too big a loss, but still it is a loss.
USING WINDOW.OPEN()
My own approach so far has been using a function based on window.open() but making sure to offer a straight HTML link to users with javascript turned off, or a nasty pop-up blocker in place.
<a href="page.html" onclick="myFunction('page.html');return false">
The return false; section keeps the original page from loading the new document if the javascript actually gets executed.
This approach does have the referrer problem, but it also gives older browsers a new window as long as their javascript is functional. In my mind, it's a trade off -- both approaches will validate. If the referrer data is important, go with Yank's solution. Where the user experience is more important, I like my approach.
[edited by: tedster at 8:18 pm (utc) on July 3, 2003]
Thanks for:
1. Feeling my frustration :)
2. Answering my question.
> So you "can" use the strict DTD, and your reasoning makes sense to me, but just don't put the W3C valid code logo on your page.
I have absolutely no desire to give W3C a free link :)
I will be using the strict DTD, just to be sure that my fingers never type align="center" out of habit.
Yes, it renders in Quirks Mode in all browsers, but I know that my code is valid and well-formed, and will therefore work reasonably well in all known browsers, is likely to work in all browsers coming out soon, and when I do hit a snag I know that I already have an easy route to compliance for the "next level up".
...just to be sure that my fingers never type align="center" out of habit
LOL - that's exactly why I've begun using strict doctypes -- to break old habits and build new ones. g1smd makes a good, pragmatic point about using transitional html - and that's exactly what I've been doing for quite a while.
But now, in the interests of staying a bit ahead of the curve, I'm building new skill set that includes class="c" instead of align="center". Hey, it's 5 fewer characters too!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
versus
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
I tend to think that it is not - unless you make your own doctype and provide an url to that.
The w3c standard doctypes are the ones that are suppported by default (except for the quirks and bugs and features), so there should be no need to download these for each site. The url is there only as a check that it is actually the right "4.0 Strict" that you are coding to - in that way, it is an integrated part of the doctype specification and shouldn't be messed with (at least it's my best guess at this time, but it is explained somewhere @ the w3c).
But now you mention it, i guess i will stay away from making my own doctype, as it can obviously require an extra 40K dwl for each user ;)
/claus
My dilema was that I wanted to use the strict DTD to avoid accidentally introducing non-strict constructs, but was worried about how browsers would react (feared they might go into quirks mode).
Tedster reassured me on that count, but a nagging unhappiness remained. I felt that, in some way, it was "wrong" to label something strict when, in fact, it was not fully comforming.
The solution turned out to be remarkably simple in the environment I use. I use a pre-processor (GTML) largely to do includes in the source code. It also has a set of conditionals, which I already used to make separate versions for export to the server and for local use (the local copy does not have the counter javascript).
So it was very simple to add another conditional, if making local copy use strict DTD, if making export copy use transitional DTD.
OK, a very minor thing, but for some reason it has made me very happy!