target="_blank"... but better ?

R

Romain

Hi,

I've used an excellent way to make target="_blank" links that still
validate while using HTML 4.01 Transitional doctypes in the past.

I learned the trick from : http://www.sitepoint.com/article/1041

Basically, instead of typing :
<a href="yourlink.html" target="_blank" alt="">The link</a>

You type :
<a href="yourlink.html" class="external" alt="">The link</a>

And it's the same due to this little piece of javascript :

/* Evite de mettre des target="_blank" */
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("class") == "external")
anchor.target = "_blank";
}
}
window.onload = externalLinks;

Now, eventhough this perfectly works, I wish I could do a little
something more (with your help).

What I would like to archieve would be the following :

When typing :
<a href="yourlink.html" class="external" alt="">The link</a>

I would like to obtain :
<a href="yourlink.html" class="external" alt="">The link</a> (<a
href="yourlink.html" class="external2" alt="">new window</a>)

So what I would like is the ability to :
1°) Add (<a href="yourlink.html" class="external2" alt="">new
window</a>) after my original link
2°) indicate by this mean that the link could be followed either on the
same page or another one.
3°) have class="external" that opens nothing and class="external2" that
opens a new window automaticaly.

What I don't know is :
1°) Is it feasible using only javascript ?
2°) Is it possible only by specifiing class="external" in the original
link (and having javascript doing the subsequent coding) ?
3°) Is someone able to come up with a solution (because I truly can't)

Hope I'll get some expert coders attention ;)

Greetings.

R.
 
D

David Dorward

Romain said:
I've used an excellent way to make target="_blank" links that still
validate while using HTML 4.01 Transitional doctypes in the past.

Oh dear. Opening new windows is not a good idea:
http://diveintoaccessibility.org/day_16_not_opening_new_windows.html

That isn't excellent, it's plain wrong and the document is still invalid.
See:
http://groups.google.com/[email protected]&output=gplain
 
S

splish

David
I've gotta say "Opening a new window" IS a good idea if it's required.
Don't forget, the bulk of surfing folk are operating a system called....
wait for it.... "Windows", hence the acceptance of windows.
Chillout pal. Write about something important.

Splishman.
 
L

Lee

"splish" said:
David
I've gotta say "Opening a new window" IS a good idea if it's required.
Don't forget, the bulk of surfing folk are operating a system called....
wait for it.... "Windows", hence the acceptance of windows.

The point is that you must develop your pages to be usable by
everybody, not just "the bulk". If you've got a commercial
web page, you may be in violation of the law if some features
aren't accessible by even a few people.
 
L

Lee

Romain said:
Hi,



Well at least it's the way I WANT IT... Maybe it's clearer now.



Ok, it's invalid. No argue about that. But still. I wasn't seeking for
your approval, rather for some enlighting pieces of code.

If you're not concerned with validity, why not simply use target="_blank"
when you want a new window and target="_self" (or "_top") when you don't?
Then it will even work for people who have disabled JavaScript.

I know that isn't the answer that you want to hear, but every now and
then somebody will actually seem to appreciate being told that the way
they're asking to do something isn't reasonable.
 
D

Douglas Crockford

I've gotta say "Opening a new window" IS a good idea if it's required.
The point is that you must develop your pages to be usable by
everybody, not just "the bulk". If you've got a commercial
web page, you may be in violation of the law if some features
aren't accessible by even a few people.

Web standards do not have the force of law. That's just nutty.
 
J

Jim Ley

Web standards do not have the force of law. That's just nutty.

However a law is free to require adherance to a web standard as part
of its application, such as current Accessibility laws which simply
cite W3's WCAG guidelines as being accessible (and it does require
validity).

Jim.
 
J

Jim Ley

David
I've gotta say "Opening a new window" IS a good idea if it's required.
Don't forget, the bulk of surfing folk are operating a system called....
wait for it.... "Windows", hence the acceptance of windows.
Chillout pal. Write about something important.

Yet the largest ISP in the world specifically markets on the fact that
it has a popup-stopper - not that it's fast, not that it's reliable,
but that it stops windows opening - are you sure they're accepted and
that ISP's marketing is just flawed?

Jim.
 
D

DU

Lee said:
"splish" said:



The point is that you must develop your pages to be usable by
everybody, not just "the bulk". If you've got a commercial
web page, you may be in violation of the law if some features
aren't accessible by even a few people.

Saying that "Opening a new window" is a bad idea is abstract, general,
without any grip on any specific case. 90% of all pages relying on popup
do not use flexible, robust cross-browser code and have no concerns
about accessibility and usability.
Nevertheless, a page using popups can be a respectable and responsible
webdesign decision.

DU
 
J

Jim Ley

Oh, and by the way, I neither live in the US nor in the UK, I don't have
a commercial web site, and I really don't care about ADA, DAA (american
only RECOMMENDATIONS).

Guessing from headers at you being in the same country as me:

http://www.w3.org/WAI/Policy/#Canada

but as you note you're not doing commercial (this would include
Government or charity or many other organisations, home publishing it
wouldn't) it matters little to you, however in discussing stuff on the
group, many of us do care, so it is still relevant to point stuff out.
I just want to offer a convenient (don't argue with that last personnal
opinion please) way to choose between opeing a link in the same window,
or in a new one, by LETTING the user do the choice.

That's good, and is certainly more accessible than most (there's
problems with what happens when you take links out of context as many
AT's do in your example but it's not too serious)

Jim.
 
L

Lee

Romain said:
Simply because I want this :

<a href="link.html" class="external">the link</a>

To be transformed into this :

<a href="link.html" class="external">the link</a> (<a href="link.html"
target="_blank">In a new window</a>)

So that users can choose between opening a link in the same window, or
not. And since all my "external" links already have the class="external"
attribute that'll be VERY convenient instead of replace each and every
link (above 5000).

All this was clearly explained in my first thread, obviously you skipped
that part.

I read that part. You did not cleary explain that you wanted the
users to be able to choose whether links were opened in the same
window or in a new one. I got the impression that you, as the
page designer, would be making that decision.
I just want to offer a convenient (don't argue with that last personnal
opinion please) way to choose between opeing a link in the same window,
or in a new one, by LETTING the user do the choice.

In that case, there is a *much* simpler way to do what you
want. Too bad you're an asshole, or somebody might help you.
 
D

DU

Romain said:
Simply because I want this :

<a href="link.html" class="external">the link</a>

To be transformed into this :

<a href="link.html" class="external">the link</a> (<a href="link.html"
target="_blank">In a new window</a>)

So that users can choose between opening a link in the same window, or
not. And since all my "external" links already have the class="external"
attribute that'll be VERY convenient instead of replace each and every
link (above 5000).

All this was clearly explained in my first thread, obviously you skipped
that part.

Oh, and by the way, I neither live in the US nor in the UK, I don't have
a commercial web site, and I really don't care about ADA, DAA (american
only RECOMMENDATIONS).

<troll>ONU made recommendations about controling guns, kyoto agreements,
not starting a war in Irak etc. USA (& UK) didn't care. Why should I
care about USA (&UK) recommendations today ?</troll>

I just want to offer a convenient (don't argue with that last personnal
opinion please) way to choose between opeing a link in the same window,
or in a new one, by LETTING the user do the choice.

And for the accessibility concerned, doing so doesn't prevent disabled
people to watch my web site (although I doubt that they will ever find
an interest to "read" my thoughts and "watch" my pictures).


R.

There is something better than target="_blank" (I am assuming here that
your website design justifies the use of popups and meets widely known
accessibility and usability requirements). Just give a name to the new
window (say, target="RequestedPopup") and then re-use the popup window.
I've coded requested popups before and I never ever saw the relevance of
creating new unnamed popup windows. Just allow the users to re-use the
same popup window, even if javascript is turned off. If you code
carefully, you can make your code robust, flexible and versatile so that
the user can open new unnamed popup windows (if this is what he really
wants and in as many new unnamed "_blank" popup windows as he wants) via
a right-click, open the referenced resource in a new tab or in the same
window... or open the reference resource in the same unique named
requested popup. The possibilities here are only limited by the browsers.

Here's a page allowing all this (use NS 7.1 or Mozilla 1.0+ to try all
alternatives):

http://www10.brinkster.com/doctorunclear/BrowserBugsSection/Opera7Bugs/Opera702Bugs.html

DU
 
N

nice.guy.nige

While the city slept said:
nice.guy.nige said:
While the city slept, Romain <[email protected]> feverishly typed:
Basically, instead of typing :
<a href="yourlink.html" target="_blank" alt="">The link</a> [...]

As an aside, there is no alt attribute for <a>, so you do not need to
declare it empty (and shouldn't really declare it at all). You can,
however use the title attribute with <a> if you wish, but it is not
mandatory.

Oups, my mistake... I mean title of course...

<g> But as I said before, title is not a mandatory attribute in <a>, so you
don't need to declare an empty one if you don't want a title.

Cheers,
Nige

--
Nigel Moss.

Email address is not valid. (e-mail address removed). Take the dog out!
http://www.nigenet.org.uk | Boycott E$$O!! http://www.stopesso.com
"How strange the change from major to minor..."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,185
Latest member
GluceaReviews

Latest Threads

Top