On Target
One thing that bothered me about XHTML is that the TARGET attribute had been dropped. This meant that opening a link in a new window required the use of Javascript or invlaid XHTML. However, thanks to the guys over at Accessify.com, I now know how to do it in a valid way.
In a nutshell, you have to define your own DTD and then use that in your HTML documents rather than a standard W3C one. If you are now panicing because this will means writing a DTD, don’t. All your DTD does is pull in the relevant definitions from the W3C and use them together. Once you’ve done that, you can use TARGET to your heart's content.
For the full lowdown and examples, check out www.accessify.com
Unfortunately trying to do this is a real nightmare in any real-world scenario as DTD’s cause lots of problems for browsers. If you then try and use some XML/XSLT transformations on the top, you get DTD Mush.
July 1st, 2005 at 9:42 amMaybe at that point you have to surrender to the Javascript method. I’ve just used this on a couple of my sites and it seems to work fine but I am not doing very technically complex sites right now.
July 1st, 2005 at 11:03 amOr perhaps stop using XHTML1 Strict. I’ve hit this recently myself.
Think about this for a minute. Why are you using XHTML? If you’re still serving pages with a mime type of text/html, what does it give you that HTML4.01 Strict doesn’t?
(IIRC, technically you’re not being standards compliant if you’re serving XHTML1Strict as text/html and seeing as IE breaks if you do that it’s not a great move right now anyway).
If you really want to use the target attribute, drop back to XHTML 1 Transitional or HTML 4 Strict. It makes life so much easier. The HTML4.01 reccomendation isn’t going away any time soon, so it’ll still be compliant.
July 1st, 2005 at 11:18 amAnd another thing. Why are you using target=”_blank” anyway? You’re taking choice away from the user. What if *I* don’t want it to open in a new window?
http://www.sitepoint.com/article/beware-opening-links-new-window
July 1st, 2005 at 11:22 amThe main reason I want to open a new window is for documents (in particular a PDF order form). Other links I am not so worried about.
Also, if the client really wants it, they will get it as they control my income at the end of the day!
July 1st, 2005 at 11:28 amFair enough on the income thing, although educating the client is never a bad thing
BTW, I’ve got an extension for Firefox called “Disable Targets for Downloads” which stops things like PDFs opening elsewhere unless I actually want them to. Personally I’d prefer it if they [PDF, DOC and other non web-native documents] were presented as downloads (so you get the Open/Save dialog), but I think that requires a bit of server-side scriptifying.
Of course I’ll be thinking about some easy way of doing that all day now, rather than the important things I should be doing…
July 4th, 2005 at 11:47 am