HTML and CSS Reference
In-Depth Information
Opening a new window using target
To open a page in a new window, you need to tell the browser the name of the window in
which to open it. If you don't tell the browser a specific window to use, the browser just opens
the page in the same window. You can tell the browser to use a different window by adding a
target attribute to the <a> element. The value of the target attribute tells the browser the
“target window” for the page. If you use “_blank” for the target, the browser will always open a
new window to display the page. Let's take a closer look:
<a target="_blank" href="http://wickedlysmart.com/buzz"
title="Read all about caffeine on the Buzz"> Caffeine Buzz </a>
Q: I'm getting a new tab instead of a new window.
Am I doing something wrong?
A: No, you're not. Most browsers now have a default
setting to open new windows in a tab, rather than a
whole new browser window, because that's what users
seem to prefer. But a new tab and a new window are
really the same thing; it's just that the tab shares the
same window border as your original window. If you
want to force a whole new window, most browsers have
a way to do this through the preferences settings.
Q: What if I have more than one <a> element with
a target? If there's already a “_blank” new window
open, will it open in the window that's already open?
Or will it open in a new “_blank” window?
A: If you give the name “_blank” to the targets in
all your <a> elements, then each link will open in a
new blank window. However, this is a good question
because it brings up an important point: you don't
actually have to name your target “_blank”. If you give
it another name, say, “coffee”, then all links with the
target name “coffee” will open in the same window. The
reason is that when you give your target a specific
name, like “coffee”, you are really naming the new
window that will be used to display the page at the link.
“_blank” is a special case that tells the browser to always
use a new window.
Open your Starbuzz “index.
html” file. Add the target
attribute to the <a> tag that
links to the Caffeine Buzz
page. Now give it a try did
you get a new window?
Can you think of some advantages and
some disadvantages to using the target
attribute to open a page in a new window?
 
Search WWH ::




Custom Search