Forum Moderators: open

Message Too Old, No Replies

DOCTYPE for almost valid code

target="_blank" and the strict DTD

         

Mohamed_E

1:53 pm on Jul 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have finished attempting to make my toy site (not the profile site) validate to 4.01 strict. I am not religeous about validation so I have made no effort to remove the traget=_blank that strict disallows. It is the only non-valid construct in the site.

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?

BlobFisk

2:05 pm on Jul 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The HTML4.01 Strict DTD is:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

claus

2:38 pm on Jul 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



there's no doctype for "almost valid" code - you have to write code that validates to a certain doctype, that's the whole point.

anyway, i dont usually use these, but isn't there some sort of "base href" or "base target" that is supported in some doctype?

/claus

BlobFisk

3:51 pm on Jul 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is a BASE target attribute, but I have a feeling that this really only applies to framesets. So, if you are specifying a base URL (www.mycompany.com) and you have a frame based design and want to specify the base target (mainFrame):

<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.

richlowe

4:18 pm on Jul 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My understanding is doctype is intended for validation engines only. Browers (at least IE) do not use it at all. [I was wrong about this - IE6 does change browser behavior based upon doctype]

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]

BlobFisk

4:21 pm on Jul 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




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]

richlowe

4:27 pm on Jul 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just chekced MSDN and I was wrong. Doctype does change the behavoir of the browser (at least IE6 and above). But there is nothing preventing you from making your own DTD.

Richard

tedster

6:53 pm on Jul 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Heck of a good question, Mohamed_E.

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]

Mohamed_E

7:51 pm on Jul 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Tedster,

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.

g1smd

8:10 pm on Jul 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Using pragmatism, based on real life browsers, I validate to HTML 4.01 Transitional, and use the short version of the DOCTYPE, without the DTD URL included.

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".

tedster

8:24 pm on Jul 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...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!

g1smd

9:18 pm on Jul 3, 2003 (gmt 0)

Pete_Dizzle

11:42 pm on Jul 4, 2003 (gmt 0)

10+ Year Member



As far as doctypes go.
I understand that without the URL some browsers wont go into standards mode.
But what I want to know is the DTD file actually downloaded because it's like 40KB?
If it is downloaded then it would be highly advantageous to not put the URL in. I checked on Mozilla 1.4 and it stays in standards mode without the URL.

<!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">

claus

12:02 am on Jul 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> is the DTD file actually downloaded

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

g1smd

6:44 pm on Jul 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>> I checked on Mozilla 1.4 and it stays in standards mode without the URL. <<

That certainly isn't the case with Mozilla 1.1 and 1.2 I know. Interesting development.

Mohamed_E

1:59 pm on Jul 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I started this thread with the question: What is the appropriate DOCTYPE declaration for a site that is almost compliant with the strict DTD?

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!