HTML: Working with Special Characters - Opening a Link In a New Window
(Page 3 of 5 )
So far the links we have created have loaded in the same browser window. This is okay if we are linking to pages within our own site. But what about when we link to someone else’s site? Or what if we just want to display a page with a small bit of information? Loading the page in a new window allows the user to view whatever page they want, without leaving our site.
To create a link that will open in a new window, we use the following code:
<html>
<body>
<a href="somepage.htm" target="_blank">New Window</a>
<p>
Setting the target to _blank forces the page to open in a new window.</p>
</body>
</html>
The above code displays the text New Window and stores the link to somepage.htm. When the user clicks the link, it will open a new browser (this occurs because we set the target as _blank), which displays the samepage.htm.
Link to a Target on the Same Page
If you are creating a page with an index on it or a page with a bunch of sections, you can use an anchor to link to specific sections of that page.
<html>
<body>
<p>
<a href="#Apples">Apples</a>
</p>
<p>
<a href="#Bananas">Bananas</a>
</p>
<h2>Section 1</h2>
<p>blah blah blah</p>
<h2>Section 2</h2>
<p>blah blah blah</p>
<h2>Section 3</h2>
<p>blah blah blah</p>
<h2><a name="Apples">How to Eat Apples</a></h2>
<p>blah blah blah</p>
<h2><a name="Bananas">How to Eat Bananas</a></h2>
<p>blah blah blah</p>
<h2>Section 6</h2>
<p>blah blah blah</p>
<h2>Section 7</h2>
<p>blah blah blah</p>
<h2>Section 8</h2>
<p>blah blah blah</p>
</body>
</html>
The above code creates two anchor tags (<a href="#Apples"> and <a href="#Bananas">) with name attributes (><a name="Apples"> and ><a name="Bananas">). When the user clicks either the word Apple or Banana, they are transported to the section How to Eat Apples or How to Eat Bananas respectively.
Next: How to Create a Mailto Link >>
More HTML Articles
More By James Payne