Alternatives to target=_blank for xhtml strict (Full Version)

All Forums >> [Web Development] >> Microsoft FrontPage Help



Message


spinningjennie -> Alternatives to target=_blank for xhtml strict (7/3/2006 6:29:29)

What is the best alternative for target=_blank when using xhtml 1.0 strict? The w3c validator rejects it. I want my external links to open in a new window, so that if a viewer closes the window, they get back to my website.

I've tried the following:

1. Used javascript in this page to link to this external.js file which contains the following code but I can't get it to work:

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

2. I've also added text beside the links in this alternative page to get the viewer to use Shift + Click to open the links. It does work but I think it looks a bit unusual.

3. As an alternative I might change my document type from Strict HTML to Transitional HTML so that target=_blank is accepted. I haven't tried this yet. I would have to compromise on strict xhtml, so I was reluctant.

Any advice much appreciated!

spinningjennie





Reflect -> RE: Alternatives to target=_blank for xhtml strict (7/3/2006 8:22:03)

I feel you.

This is the best I could do using strict myself. It is also JS, which IMHO, is a waste or code bloat. I just want to validate to strict so I need to add another ten lines of code [:@].

http://weblogtoolscollection.com/archives/2004/01/02/targetblank-xhtml-10-strict-conversion/

Anyone have a better solution?

Take care,

Brian




Tailslide -> RE: Alternatives to target=_blank for xhtml strict (7/3/2006 8:38:39)

If you're sure you want to use a pop-up then use this:

<a href="some.html" onclick="return ! window.open(this.href);"> some place</a>


That way, if people have JS off then it just opens within the same window. Do make sure you warn people that it opens in a new window though!




spinningjennie -> RE: Alternatives to target=_blank for xhtml strict (7/3/2006 22:10:45)

Thanks so much Reflect and Tailslide!

1. Tailslide's suggestion works very neatly with little code.

2. Reflect, the link you provided gave the SitePoint link where I got the javascript code in my 1st post. I've now got that external.js file to work. I just needed to add the last line of code:

window.onload = externalLinks;

A big thanks!

spinningjennie




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.109375