Markup: "Target" attribute

started by Vladimir on Apr 18, 2004 — RSS Feed

Vladimir Vladimir
Posts: 53

Hi all,

One of my XHTML Strict pages uses the "target" attribute in the element "a". I used the W3 validator and it said that this attribute didn't exist. ??? But there isn't any alternative. What can I do?

Thanks.

Joe Gillespie Joe Gillespie
Posts: 528

Don't use 'strict' - that's only for masochists!

Baxter Baxter
Posts: 157

I always use strict.  Maybe I am a masochist, but it's the fastest way to force the browser into compliant rather than loose mode, and if it validates in strict, it's clean. But maybe I am a masochist.

I can't recall if I've run into this problem before and how I handled it, but a quickie google search suggested passing it off to the onclick function, like so:

<a href="foo.html" onclick="window.open('foo.html'); return false">foo</a>

Joe Gillespie Joe Gillespie
Posts: 528

The tree that bends with the wind seldom breaks

Vladimir Vladimir
Posts: 53

Baxter said:
I always use strict.  Maybe I am a masochist, but it's the fastest way to force the browser into compliant rather than loose mode, and if it validates in strict, it's clean. But maybe I am a masochist.

I can't recall if I've run into this problem before and how I handled it, but a quickie google search suggested passing it off to the onclick function, like so:

<a href="foo.html" onclick="window.open('foo.html'); return false">foo</a>


If you use the onclick function, however, won't pop-up blockers be activated? Because I don't think they block the "target" attributes though.

Baxter Baxter
Posts: 157

Good question, and offhand I don't really have an answer.
Try it and see. At most, yer out five minutes time, trying.

A really ugly, dirty solution would be to use document.write to insert the target function, but even if it worked, it'd be an ugly hack.

Here's a really high-zoot way of doing it that's way to complex for me to summarize here, but it looks like the author REALLY knows what he's talking about.

http://www.accessify.com/tutorials/standards-compliant-new-windows.asp

Joe Gillespie Joe Gillespie
Posts: 528

That stuff makes my brain itch and I can't scratch it. If they are talking about accessibility, why isn't it more accessible to humans? It's no wonder people shy away from 'strict'!!!

Baxter Baxter
Posts: 157

Do not fear "strict"... it has a clearly defined and relatively simple set of rules, and as long as you stay within them, your pages WILL work, and they'll work more reliably, as all browsers will be in compliant mode. Browsers in loose mode make my brain itch. Just too hard to remember all the differences.

Target is a funny thing, though. If it were me I'd ask myself "do I REALLY need this open in a new window"? If so, I'd probably use the simple onclick method.

Joe Gillespie Joe Gillespie
Posts: 528

But, IE in Strict mode is a quite different animal than Mozilla in Strict mode. Where do you what to go today?

Vladimir Vladimir
Posts: 53

Well if you really wanted to write standards-compliant code, then you wouldn't want to use deprecated elements, which would then be classified as "strict"... I mean what's the point of using XHTML if you're still using font tags?

Baxter Baxter
Posts: 157

Yes, but they're much closer in strict than they are in loose. In strict, you're pretty much just worrying about the box model. In loose, all kinds of funky stuff can go down.

And who said anything about font tags?

Vladimir Vladimir
Posts: 53

Font tags are deprecated elements, are they not?  

Baxter Baxter
Posts: 157

Yes, but what's that got to do with anything? There's NO good reason to use a font tag, and since no one mentioned them, I'm having trouble understanding where they fit in.

Graham Graham
Posts: 7

So is the common wisdom to just keep using Transitional?  Or just stop wanting to open new browser windows... or use hacks to do it?  Hmm.

Graham

Baxter Baxter
Posts: 157

I think the smart thing is to ask yourself "WHY am I opening a new window?"

If there's a good reason, there's probably a clear solution to the problem.

Or maybe not, in which case, use transitional and don't lose any sleep over it.

I don't really understand why the deprecated it without having a clear replacement mechanisim in place. I mean, I understand WHY they deprecated it (separation of behavior from content), but I don't understand why they dropped it without offering up a good alternative method.

Graham Graham
Posts: 7

Right... I guess that's my problem with it.  No clear replacement.

I'm opening a new window on links that are external to the site.  Now, I guess I don't have to do this, and people can learn to use their back-button and/or history to find their way back.  Does this sound reasonable based on your own browsing habits?

Graham

Kk5st Kk5st
Posts: 15

The target attribute is deprecated in html4 and xhtml for all elements since windows and frames are outside the scope of pure document markup.

If you really can't do without it, use scripting to open the new window.  That's the desired w3 method.

cheers,

gary

You must login to reply