468,168 Members | 1,538 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,168 developers. It's quick & easy.

target="_blank"... but better ?

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[i];
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.
Jul 20 '05 #1
12 2904
Romain wrote:
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...w_windows.html
I learned the trick from : http://www.sitepoint.com/article/1041


That isn't excellent, it's plain wrong and the document is still invalid.
See:
http://groups.google.com/groups?selm...&output=gplain
--
David Dorward http://david.us-lot.org/
Jul 20 '05 #2
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.
"David Dorward" <do*****@yahoo.com> wrote in message
news:bf*******************@news.demon.co.uk...
Romain wrote:
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...w_windows.html
I learned the trick from : http://www.sitepoint.com/article/1041


That isn't excellent, it's plain wrong and the document is still invalid.
See:

http://groups.google.com/groups?selm...&output=gplain

--
David Dorward http://david.us-lot.org/

Jul 20 '05 #3
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.

Jul 20 '05 #4
Lee
Romain said:

Hi,

In article <bf*******************@news.demon.co.uk>,
David Dorward <do*****@yahoo.com> wrote:
Romain wrote:
> 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...w_windows.html


Well at least it's the way I WANT IT... Maybe it's clearer now.
> I learned the trick from : http://www.sitepoint.com/article/1041


That isn't excellent, it's plain wrong and the document is still invalid.
See:
http://groups.google.com/groups?selm...0%40news.demon.
co.uk&output=gplain

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.

Jul 20 '05 #5
> >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.


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

Jul 20 '05 #6
On Fri, 25 Jul 2003 13:49:04 -0700, "Douglas Crockford"
<no****@laserlink.net> wrote:
>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.


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.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #7
On Sat, 26 Jul 2003 02:02:44 +1000, "splish" <cm*@congosystems.com>
wrote:
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.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #8
DU
Lee wrote:
"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.


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
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/

Jul 20 '05 #9
On Sat, 26 Jul 2003 12:47:27 -0400, Romain <us**@domain.tld> wrote:
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.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #10
Lee
Romain said:

In article <bf*********@drn.newsguy.com>,
Lee <RE**************@cox.net> wrote:
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.
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.

Jul 20 '05 #11
DU
Romain wrote:
In article <bf*********@drn.newsguy.com>,
Lee <RE**************@cox.net> wrote:

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.

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/doctorunc...ra702Bugs.html

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/

Jul 20 '05 #12
While the city slept, Romain <us**@domain.tld> feverishly typed:
In article <bg************@ID-112325.news.uni-berlin.de>,
"nice.guy.nige" <ni********@deadspam.com> wrote:
While the city slept, Romain <us**@domain.tld> 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. ni***@nigenetDOG.org.uk. Take the dog out!
http://www.nigenet.org.uk | Boycott E$$O!! http://www.stopesso.com
"How strange the change from major to minor..."
Jul 20 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Sugapablo | last post: by
16 posts views Thread by St. Rechsteiner | last post: by
8 posts views Thread by msnews.microsoft.com | last post: by
5 posts views Thread by Jon via DotNetMonster.com | last post: by
1 post views Thread by =?Utf-8?B?Sko=?= | last post: by
1 post views Thread by gcdp | last post: by
reply views Thread by kamranasdasdas | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.