Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

target ="_blank" not valid 4

Status
Not open for further replies.

JillC

Technical User
Jan 10, 2001
241
AU
I've just been validating my code, which all conforms apparently except for a link which I am using target ="_blank" to open a new window. It tells me that I need to use transitional instead of strict if I want to use this code. Is there an alternative to this code in strict xhtml?

I'm confused.
 
it seems a shame that you have to resort to javascript to open a link in a new window

Consider that:
HTML is for defining document structure
CSS is for defining style/appearance
Javascript is for defining behaviour

Now consider which of those three catagories opening a new window falls under.

Javascript is wholly appropriate to open new windows.

The script linked to is more or less how I do it. But if you only have 1 link it can be a little overkill. In that instance you may wish to consider a little inline JS (though, this does break the seperation of style/content/behavior idea)

Code:
<a href="foo.html" onclick="window.open(this.href); return false;">Clicky clicky</a>

<honk>*:O)</honk>

Earl & Thompson Marketing - Marketing Agency Services in Gloucestershire
 
Thanks very much. I've given you ALL a star!

The links on this forum actually open a new window. It would drive me batty if they didn't! However all the articles together provided me with a good discussion of the problem and solutions.

Now, I guess the next trick will be for someone to work out how to get the new window to be a tab in IE7 like it does in Firefox? (Not that I'll worry about it for now)

Thanks, Jill.
 
See, given the link has no behaviour, anyone can choose whether they want to open it in the same window, another window or another tab. I personally open many links with middle mouse button, which in IE7 and FF means new tab.
 
The target attribute is valid and correct in XHTML strict PROVIDED YOU ARE USING A FRAMESET DTD where a target frame is to be expected.

It is NOT a deprecated attribute as is often incorrectly stated in some places, it's use is merely being limited to the DTD where it has practical use.

Of course, you can use target on any links you wish and with any DTD including strict, and it will work quite happily, just not validate, and if you really want to use target AND have it validate against a DTD you could always write your own DTD and link to that.

Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
See, given the link has no behaviour, anyone can choose whether they want to open it in the same window, another window or another tab. I personally open many links with middle mouse button, which in IE7 and FF means new tab.


That's the critical point right there.
Let the visitor choose how to interact with your site, don't impose your will on them.
After all, who knows what suits a visitor best? The site creator or the visitor themself?

* for Vragabond


<honk>*:O)</honk>

Earl & Thompson Marketing - Marketing Agency Services in Gloucestershire
 
I hardly ever have my code open links in a new window, for reasons enumerated above. If I want to do so as a surfer, shift-click opens links in a new window, ctrl-click gets a new tab.

The only time I consider new-window behaviour is when the linked document needs to be viewed in conjunction with the current one. A help page is the classic example - I'm having trouble here, so I want to view help in another document side-by-side. External links in Tek Tips could be viewed in the same light - they're pages germane to an ongoing discussion on this site, we want to see them alongside the thread rather than instead.

To be honest, on those rare occasions I need a new window, I just use the target attribute and ignore any validation errors it may cause.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top