473,805 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getE lementsByTagNam e) return;
var anchors = document.getEle mentsByTagName( "a");
for (var i=0; i<anchors.lengt h; i++) {
var anchor = anchors[i];
if (anchor.getAttr ibute("href") &&
anchor.getAttri bute("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="external 2" alt="">new window</a>)

So what I would like is the ability to :
1°) Add (<a href="yourlink. html" class="external 2" 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="external 2" 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
12 3322
Lee
Romain said:

In article <bf*********@dr n.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*********@dr n.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="Request edPopup") 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.tl d> feverishly typed:
In article <bg************ @ID-112325.news.uni-berlin.de>,
"nice.guy.n ige" <ni********@dea dspam.com> wrote:
While the city slept, Romain <us**@domain.tl d> 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***@nigenetDO G.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
7688
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. Any ideas? --
1
1968
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
3621
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! ... Why? Is there no "same effect"-Tag in xHTML? Thx for answers!
6
77512
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 which allows me to specify 'target=' on an anchor tag. -- Tony Marston http://www.tonymarston.net
2
2847
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 clicks submit button on page2.asp, I expected to open a new window called page3.asp. Unfortunately, it just open page3.asp in the same window as page2.asp, and now page2.asp is gone. However, if I just open page1.asp, and begins from there, it is...
10
60728
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 worked very well a long time, but now it does not work anymore. We use IE6 and Microsoft Windows XP Professional 2002 SP2. I guess it has something to do with new IE security features. Does
8
3863
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 links to external sites. The hyperlink columns have the target="_blank" attribute so they preserve the existing window. This works OK except that the NavigateURL's are quite long due to the size of the query string and this makes the page slow. ...
5
3992
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 site in a new window using the above code in my asp.net web.sitemap. I'm expecting the target="_blank" bit to make it do this. but it isnt. Does anyone know why?? Thanks in advance.
1
4631
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 bulletedlist that I populate at runtime (so that I can put a request variable on the link in the listitem's value property). <asp:BulletedList runat="server" ID="lstHelp" Target="_blank" DisplayMode="HyperLink"></asp:BulletedList> This all works...
0
9718
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10369
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.