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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Any way to do target="_blank" and still validate strict? 2

Status
Not open for further replies.

GulfImages

Technical User
Jul 9, 2004
60
US
I'm doing a freebie for a non-profit and since it is an organization for the visually impared, I'm trying to validate to strict. For some links on a page, I want them to open in a new window so I used target="_blank" which of course doesn't validate to strict. Is there some other method open a link in a new window and still validate to strict?

<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "
Thanks,
Bobby
 
Yep. Try this

Code:
<a href="apage.html" onclick="window.open(this.href); return false;">Visit another page</a>

Even with Javascript disabled the link will work, just load in the same window.

An even better way would be to remove the onClick event to an unobtrusive script outside the HTML and attach it to the link via a class or a specific ID... or some other way that suits your document structure.

<honk>*:O)</honk>
Foamcow Heavy Industries - Web site design in Cheltenham and Gloucester
Earl & Thompson Marketing - Marketing Agency Services in Gloucestershire
 
the accepted workaround for this is applying a class name to the links you'd like to open externally, then, when the page loads, call a javascript function to loop through the anchor elements, test for the specified class name, and apply a function to it. the function will open a new window and load the URL.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
I'm doing a freebie for [...] an organization for the visually impared [...] For some links on a page, I want them to open in a new window
Are you sure this is a good idea? Opening new windows can cause real accessibility issues for vision-impaired users, see for why.

If you, and your client, really want the site to work this way, try the script outlined in for a slick and valid way to do it.

Incidentally, it's a bad idea to include the [tt]<?xml version="1.0" encoding="iso-8859-1"?>[/tt] in an XHTML document as it confuses IE6 and throws it into quirks mode. It's optional anyway, so you can safely get rid of it.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
While I agree with the concept that the new window could be a bit of a problem with some readers other than Jaws, this is a very insignificant link that is obviously going away to an entirely new site so it shouldn't be a real issue in this case. I don't agree about the issue of the back button in the article, that's a little overblown IMHO. I only use new windows when sending the user off to a completely different site. I appreciate the info, very good stuff at that site.

I didn't know that about the ?xml statement. Is there any reason at all that it should be there? What am I missing if I remove it?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top