HTML links with target - html

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:
Click here
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?

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
first link
second link

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:
_self: Load the response into the same HTML4 frame (or HTML5 browsing context) as the current one. This value is the default if the attribute is not specified.
_blank: Load the response into a new unnamed HTML4 window or HTML5 browsing context.
_parent: Load the response into the HTML4 frameset parent of the current frame or HTML5 parent browsing context of the current one. If there is no parent, this option behaves the same way as _self.
_top: In HTML4: Load the response into the full, original window, canceling all other frames. In HTML5: Load the response into the top-level browsing context (that is, the browsing context that is an ancestor of the current one, and has no parent). If there is no parent, this option behaves the same way as _self.

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.

Related

Why would links in an object or iframe (I've tried both) start opening in a new window

I'm working on an application that has many links. They all open in the same window, until today. All of a sudden, in all browsers I'm testing in, 3 links in an iframe or object (I've tried both) start opening in a new window. I can't seem to stop this.
An object example follows. The dolnks program generates 3 simple links like the one following the object example and these links open in a new window.
<OBJECT ID='fixed' DATA='dolnks.cgi?str=$params' TARGET='dynamic' NORESIZE></OBJECT>
darea.cgi?str=$dogstr
Can someone help me understand this and how to get these links to open in the same window.
All links that now open in the same window or should be opening in the same window are from
the same domain.
I now have to close the link instead of using the back button.
Thanks,
craigt
I imagine it's because of your TARGET attribute, although it's not using one of the special target values:
target
Where to display the linked URL, as the name for a browsing context (a tab, window, or ). The following keywords have special meanings for where to load the URL:
_self: the current browsing context. (Default)
_blank: usually a new tab, but users can configure browsers to open a new window instead.
_parent: the parent browsing context of the current one. If no parent, behaves as _self.
_top: the topmost browsing context (the "highest" context that’s an ancestor of the current one). If no ancestors, behaves as _self.
From the MDN Docs: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attributes
Note though that the docs for object do not list a target attribute, so that behavior is apparently undefined, and probably varies depending on the browser, and the plugin displaying the object.
Check to see if it's the items with a target attribute (case does not matter) that are working "wrong", and see if removing that attribute fixes it. If that's not it, next check to see if there are javascript being loaded. Try turning javascript off (hopefully the relevant links are not generated with javascript) and see if that fixes the behavior. If turning javascript off is too heavy handed, you can use the javascript console to see what listeners are attached to the links.

What is the difference between action and target of post?

I looked for attribute of form on W3S - HTML Forms page and I saw that, there are two similar attributes, at least I suppose that. I don't understand differences between them. So I want to ask, What is the difference between action and target of post?
action is where the data is sent, target is which window (or tab, frame, iframe) to use for the request. If action is omitted, it assumed to be the current page (the same URL). If target is omitted, it is assumed to be the same window (or tab).
Using target="_blank" always opens in a new window (or tab, frame, iframe). You can use a name for the window so that all links/forms with target="karl" would always open in the same window or tab.
This is the actual (current) HTML5 standard information on the form element: http://www.w3.org/TR/2014/REC-html5-20141028/forms.html#the-form-element

What does _top in the hyperlink target do?

I sometimes see target="_top" in an anchor tag. What does it do?
Foobar
target=:
_top: Opens the linked document in the full body of the window
_blank: Opens the linked document in a new window or tab
_self: Opens the linked document in the same frame as it was clicked (this is default)
_parent: Opens the linked document in the parent frame
framename: Opens the linked document in a named frame
http://www.w3schools.com/tags/att_a_target.asp
If the link is in an iframe, the new webpage will not be loaded in the iframe but instead the browser will open the page in the window itself
It's a browsing context name.
A valid browsing context name or keyword is any string that is either
a valid browsing context name or that is an ASCII case-insensitive
match for one of: _blank, _self, _parent, or _top.
Take a look at the matrix here, which describes the behavior of the target attribute in different scenarios.
The practical effect is that _top references the topmost window (technically the top level browsing context).
a link tells the browser to navigate to "foo.com" not in its own frame, but in the topmost frame. If the current frame is the topmost frame, the URL will open in the same window.
See also: Browsing Contexts (if you're in the mood for some deep reading).
target="_top" will open the link at the top level of all defined framesets.
as #hamon said
Example to use _top with jQuery
If your site is contained in a frameset
$(document).ready(function() {
if(top.location != location) {
$('a, form').each(function() {
if(!this.target) {
this.target = '_top';
}
});
}
});
So.. All links in your site gonna open in new window not in the frame (Credit)
target="_top" attribute causes the "target" of the hyperlink to display at the top level of all currently defined framesets. It opens the linked document in the full body of the window
From : http://www.w3schools.com/tags/att_a_target.asp

Html: open the page in a new window. target="_blanck" - is that a typo?

I have found (with a letter c)
target="_blanck"
instead of expected
target="_blank"
in a project written by someone else.
It works and opens a link in a new window.
Is that a typo or am I missing something?
The target attribute refers to where the contents of the link will be loaded in your browser. The browser will put the contents of the page inside the window/frame with that name, as long as it's not one of the special values _blank, _self, _top or _parent. See the Frame target references section in the w3 spec.
Except for the reserved names listed below, frame target names
(%FrameTarget; in the DTD) must begin with an alphabetic character
(a-zA-Z). User agents should ignore all other target names.
The following target names are reserved and have special meanings.
_blank The user agent should load the designated document in a new, unnamed window.
_self The user agent should load the document in the same frame as the element that refers to this target.
_parent The user agent should load the document into the immediate FRAMESET parent of the current frame. This value is equivalent to _self if the current frame has no parent.
_top The user agent should load the document into the full, original window (thus canceling all other frames). This value is equivalent to _self if the current frame has no parent.
So, if the link is supposed to always open a new window, it should be _blank. If there are several links with the same target=_blanck, it might be like this on purpose if they're supposed to always replace the contents of the same window.
See this fiddle:
This opens SO always in a new window
This opens google in a given window
This opens SO in the same given window
Yes its a typo
target="_blank"
Will open in a new window
target="_blanck"
Will open in a tab named blanck, if there is not a tab named blanck it will open a new one.
My guess is if you click that link it will open in a new window, click it again and it will reload the same tab it opened previously
The correct way is:
Home
The main method to give hyperlink in HTML is,
CLick Here ...
where is HTML tag and href and target is attribute. If you write target="_blanck" its means that you have an HTML page named _blanck and its gives you error.

HTML attribute "target" in links: browsing context

There seems to be an odd behavior when using the target attribute in a link, e.g.:
<ul>
<li>Opernhaus</li>
<li>Powerhouse Museum science+design</li>
<li>Botanic Gardens</li>
</ul>
The last link causes that whatever link is clicked afterwards a new browser window is being opened. The expected behavior is to open the link in the browsing context "sehenswuerdigkeit" (= "place of interest"). All other links work fine. It seems like opening this site destroys the browsing context.
I've tried it using Chrome 17, Safari 5.0.1 and Firefox; working on Mac OS 10.5.
I believe it's actually the second link sir...it is corrupting the target with javascript.
http://www.powerhousemuseum.com/
target in this sense is not a location, it is for the browser to tell what it needs to do.
Try making target="_self", and putting that property value of sehenswuerdigkeit in another property.\
Also, what is the expected behavior, 'sehenswuerdigkeit' is not a target, and I'm not sure what you mean by 'browsing context' in your request.
There are only a few values that are valid for the target attribute:
_blank Opens the linked document in a new window or tab
_self Opens the linked document in the same frame as it was clicked (this is default)
_parent Opens the linked document in the parent frame
_top Opens the linked document in the full body of the window
framename Opens the linked document in a named frame