Click to See Complete Forum and Search --> : <a href="blabla.html" target="_blank"> not valid</a>


acemo
01-08-2006, 05:38 PM
I get this error when trying to validate my page as xhtml

Error Line 222 column 41: there is no attribute "target".

...><a href="img/gallery/=O.JPG" target="_blank"><img src="img/gallery/=O.JPG" h

My question: How to open a link in a new window in valid xhtml?

NogDog
01-08-2006, 05:54 PM
My question: might you reconsider the need to open a new window? (The basic idea here is that various user agent options may prevent such data from being presented, such as pop-up blockers and other browser options the user may have enabled.)

If you are not worried about this and only care about being able to say, "My markup passed the w3.org validator," then your likely option is to use JavaScript to open the window (which, of course, is probably even more likely to be stopped by pop-up blockers).

acemo
01-08-2006, 06:06 PM
I basicly got my gallery to open the pictures in a new window.

javascript is not an option for me, my site is and will be 100% w.o javascript.

http://80.60.218.3/oob.com/gallery.php
heres the page if u wanna kno (yes am gonna make thumbnails for the pics, i kno they load LONG atm)

What do u think will be best option?
1) redirect em to a page with the picture and a back button.
2) just link straight to the picture (in the same window).
3) something else.

felgall
01-08-2006, 06:07 PM
The current web standards say that you should leave it to your visitors to decide when they want to open a page in a new window and when they want to reuse the existing one. All of the target attributes have therefore been deprecated. You can therefore still get your page to validate if you use a transitional doctype but not with a strict one.

v_Ln
01-09-2006, 03:58 AM
I know you said your site would be 100% w/o javascript but incase you reconsider this will convert your valid links into ones which will open in a new window. and it is not effected by popup blockers.

// Create valid external Links

function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
window.onload = externalLinks;

then on whichever links you want to open in a new window use something like :

<a href="http://www.blah.com/" rel="external" >Valid link</a>

note the rel="external" this is what is required to change it so it opens in a new window.


- i cant take credit for this script but i cant seem to find where i found it either to give proper credit >.<

Fang
01-09-2006, 04:56 AM
- i cant take credit for this script but i cant seem to find where i found it either to give proper credit >.< Possibly http://www.sitepoint.com/print/1041

The method adds invalid attributes; your just fooling the W3C validator, but it doesn't make it valid!

Let the user decide. Right click "Open link in ..."