...

View Full Version : target="_blank" in XHTML 1.0 Strict



missing-score
03-07-2004, 08:42 PM
Hey, on my most recent design I have some links that I would like opened in a new window, however if I add the target attribute it says that it doesnt exist. i have looked but cant find a way around opening links in a new window? Anyone know how? Thanks.

Antoniohawk
03-07-2004, 08:48 PM
http://development.incutio.com/simon/targetBlankExperiment.html

http://faq.ozoneasylum.com/834/rating/

me'
03-07-2004, 09:03 PM
target-new: newSoon...

missing-score
03-07-2004, 09:04 PM
ok thanks for that, the only problem is most of my links dont actually have a class name, does this mean I would need to make a class for the links?

coothead
03-07-2004, 09:28 PM
Hi there missing-score,

This code does not rely on 'class' but on tag name...


<script type="text/javascript">
//<![CDATA[
function setTarget(){
var a = document.getElementsByTagName("a");
for(var i = 0;i < a.length;i++){
a[i].target = "_blank";
}
}
//]]>
onload=function() {setTarget();}
</script>


c:D:Dthead

missing-score
03-07-2004, 10:47 PM
cheers thanks ill get it added soon :)

missing-score
03-07-2004, 10:58 PM
Thanks, it works! however I will make a separate class for new window links as some links I want to open in the same window so It will just make life easier.

Thanks for your help :)

EDIT: Got it working, and I will upload it tomorrow :thumbsup:

Nightfire
03-07-2004, 11:02 PM
I maybe wrong but I always thought that new windows should be opened by the users choice, not yours. Which is why they stopped using that in xhtml.

missing-score
03-07-2004, 11:04 PM
I can see your point, and I know if people are going to leave my site then a new window wont stop them... but I would rather have off site links open in a new window, and also it allows me to break out of the frame I am stuck in for the off site links.

Tails
06-10-2004, 07:05 AM
I may be wrong, but you don't need a script for this. Just modify the DTD to suit your needs. The W3 Validator didn't have a problem with this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" [<!ATTLIST a target CDATA #IMPLIED>]>

]|V|[agnus
06-10-2004, 03:18 PM
target-new:

is that a forthcoming CSS property? i hope they reconsider. i find even the slight blurring of presentation and behavior with :hover a bit odd. a more knowledgeable gentleman than myself has written an article on the topic that's worth checking out. he doesn't draw any conclusions necessarily about whether even :hover should or should not be a part of CSS, so it's more of a 'get ya thinking' type piece. very interesting observations. for instance, the CSS methods for rollout menus are extremely efficient and compact on the code side, but what sense does it make using the presentation layer to control behavior? etc.

http://digital-web.com/articles/separating_behavior_and_presentation/

llizard
06-10-2004, 03:18 PM
I would rather have off site links open in a new window

Why don't you just add a title spec so that when you viewers mouseover the offsite link, it says something like title="this is an offsite link"? And to have the offsite link(s) break out of your frame, put target="_top" into the link.

]|V|[agnus
06-10-2004, 03:37 PM
Because, as he said, he is using XHTML strict which has deprecated the "target" attribute..

llizard
06-10-2004, 06:02 PM
|V|[agnus']Because, as he said, he is using XHTML strict which has deprecated the "target" attribute..

In which case, it seems that frames cannot be used if he is using XHTML strict.... ie: frames
are supported in the w3c.org XHTML 1.0 strict doc type.

(I have stared and stared at what appears to be English in


http://www.w3schools.com/xhtml/xhtml_reference.asp
http://www.w3.org/MarkUp/
http://www.w3.org/TR/2002/REC-xhtml1-20020801/dtds.html#a_dtd_XHTML-1.0-Frameset

and cannot understand how one would get links to open in various frames if target= is not allowed - not that it matters though - I've never been a big fan of frames anyway)

And personally, I would still advocate the use of title="this is an offsite link" over opening in a new window.

]|V|[agnus
06-10-2004, 06:06 PM
It's deprecated in the Strict DTD, but not the Transitional DTD. So, I believe the proper use of the XHTML frameset would be to then use XHTML Transitional or HTML pages within the frames.

But I dunno. I avoid frames like the plague now.

llizard
06-10-2004, 06:20 PM
|V|[agnus']I believe the proper use of the XHTML frameset would be to then use XHTML Transitional or HTML pages within the frames.

So why wouldn't they say that then?

(I loathe and despise frames almost as much as offsite links that open in new windows - it's gotten to the point that I right click on links and paste them into the location window JUST so I won't have a new browser opening.)

]|V|[agnus
06-10-2004, 07:05 PM
So why wouldn't they say that then?

(I loathe and despise frames almost as much as offsite links that open in new windows - it's gotten to the point that I right click on links and paste them into the location window JUST so I won't have a new browser opening.)

Regarding your question: it might be because what I said isn't entirely correct. I dunno, but it makes sense to me... if you're using frames, you need "target", so therefor you need the Transitional XHTML DOCTYPE. *shrug*

As for links opening in new windows, you could keep right clicking, or you could just use Firefox and use the middle mouse button (if you don't have one, but you have a scrollwheel, that probably functions as a button too) and you can open it in a new tab with a single click.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum