Reputation: 73
I asked this previously in another place and got no useful replies.
One of the possible uses of the "target" attribute on an HTML link is to specify a named window, like:
<a href="somepage.html" target="mySpecialWindow">Click here</a>
Presumably the reason for naming a target, as opposed to just using "_blank", is that you want to be able to reference that SAME window for other links. For example, say you have a main page that you want to always remain in view, which has links to several help pages, and you want all of those help pages to open in a specific secondary window. So clicking the first help link opens the secondary window, clicking a second help link replaces the contents of the secondary window with a different help page, clicking the third help link replaces the contents of that secondary window again, etc.
But the existing browsers (Firefox, Chrome, etc.) do not do this. If you use a target attribute on your links with a specific (identical) window name, clicking those links opens a new, separate window with each click, even though the target name is the same. In other words, it behaves exactly as if you used target="_blank".
Why is this? What is the point of having the ability to name target windows if naming a window acts exactly the same as using target="_blank" ?
And is there any way to make a link actually use an existing window that has been opened with the same name instead of opening yet another window?
Upvotes: 3
Views: 1728
Reputation: 25830
Have you tried it using Javascript?
//You keep a reference to the window
var mySpecialWindow = undefined;
function openInSameWindow(url)
{
//First time opening
if ( typeof( mySpecialWindow ) === "undefined" )
{
mySpecialWindow = window.open(
url,
"mySpecialWindow",
"width=300, height=250"
);
}
//Use existing popup window/tab
else mySpecialWindow.location.href = url;
return false;
}
//html
<a href="#" onclick="openInSameWindow('http://someurl.com')">first link</a>
<a href="#" onclick="openInSameWindow('http://someotherurl.com')">second link</a>
Upvotes: 1
Reputation: 27460
Attribute "target" allows to load documents into particular frame/iframe on the page. It is far from windows in these "tab days" but rather about views - containers of [sub]documents.
Upvotes: 0
Reputation: 761
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a
This attribute specifies where to display the linked resource. In HTML4, this is the name of, or a keyword for, a frame. In HTML5, it is a name of, or keyword for, a browsing context (for example, tab, window, or inline frame). The following keywords have special meanings:
Upvotes: 0