473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 3259
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Sugapablo | last post by:
I admit, I'm terrible creating reg ex's. I'm trying to create a preg_replace that would remove from a <a href> tag that would replace the target attribute regardless of what the value might be....
1
by: Nick Messick | last post by:
I'm going through some old code and have found this a number of places. Seems kind of strange. Is there any reason why someone would do this?
16
by: St. Rechsteiner | last post by:
Hi How i made the same effect in xHTML like the - target="_blank" - Tag in HTML 4.01? I will use it with xHTML and CSS ... but the validator say's to me, that this tag wasn't valid for xHTML!...
6
by: Tony Marston | last post by:
The code <a href="..." target="_blank">...</a> will not validate as XHTML STRICT because of the 'target' tag, so how do I achieve the same result by moving it to a CSS file? I cannot find anything...
2
by: Matt | last post by:
In the following code, page1.asp is inside the frame of main.html. When the user click submit button in page1.asp, it will submit the form and open a new window called page2.asp. When the user...
10
by: Dieter Salath? | last post by:
Hi, in our webpage, a user could open a windows explorer to his temp directory with a simple link and usage of the file protocol: <a href="file://C:\temp" target="_blank">C:\temp</a> This...
8
by: msnews.microsoft.com | last post by:
I want to redirect the user to a url outside of our website but I want it to preserve our application's window by opening a new window. We have a datagrid that has five hyperlink columns containing...
5
by: Jon via DotNetMonster.com | last post by:
<siteMapNode title="share price" description="Link to Netcall on the London Stock Exchange" url="http://www.yahoo.co.uk" role="" target="_blank" /> Hi all I'm trying to open the Yahoo web...
1
by: =?Utf-8?B?Sko=?= | last post by:
Hi all, I have a help page that I have to (against my better judgement) open up in a new window, which will show the help for the current page the user is on. So in my master page I have a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.