09. HTML Links

HTML Links

A link is the "address" to a document (or a resource) located on the world wide web or elsewhere within your own web server.

<html>
<body>
<p>
<a href="lastpage.htm">
This text </a> is a link to a page on this web site.
</p>
<p>
<a href="http://www.microsoft.com/">
This text</a>is a link to a page on the world wide web.
</p>
</body>
</html>

Open a Link in a New Browser Window
The target attribute enables you to control how the browser responds when you click on the link.

<html>
<body>
<a href="lastpage.htm" target="_blank">Last page</a>
<p>
If you set the target attribute of a link to "_blank", the link will open in a new window
</p>
</body>
</html>

Hyperlinks,Anchors, and Links

hyperlink is a reference (an address) to a resource on the web.
HTML anchor is a term used to define a hyperlink destination inside a document.
the anchor element <a> defines both hyperlinks and anchors.

HTML Link syntax
the start tag containes the attributes about the link
<a href="link" > link text</a>

the element content does not have to be text

href attribute
it defines the link "address"
<a href="http://www.w3schools/">visit w3schools</a>

the Target attribute
it defines where the linked document will be opened

<html>
<body>
<a href="http://w3schools.com/" target="_blank">this link open in new window</a>
<p>If you set the target attribute to blank it will open the document in new window</p>
</body>
</html>

Option Description
_blank opens a linked document in a new window
_self opens a linked document in the same frame as it was clicked (this is defult)
_parent opens the linked document in the parent frameset
_top opens the linked document in the full body of the window
framename opens a linked document in a named frame

The name attribute
Named anchors are sometimes used to create a table of contents at the beginning of a large document.
each chapter within the document is given a named anchor and links to each of these are put at the top of the document. no errors occurs

named anchor syntax:
<a name = "lable">any content</a>

the link syntax to a named anchor:
<a href ="#label">any content</a>
the # in the href defines the link to the named anchor.

<a name="tips">useful tips section</a>
a link to the "useful tips section" from elsewhere in the same document
<a href="#tips">jump to the useful tips section</a>

a link to the "usefull tips section" from another document
<a href = "http://www.w3schools.com/html_tutorial.htm#tips">jumps to the usefull tips section</a>

Note:always add a traling slash to sub folder references. if you link like this:
href="http://www.w3schools.com/html" you will generate two http requests to the server because the server will adds the slash to the address and creats a new requset like this:
href="http://www.w3schools.com/html/".

Links on the same page

<html>
<body>
<p>
<a href="#c4">see also chapter 4.</a>
</p>
<h2>chapter1</h2>
<p>this chapter explaines ba bla bla</p>

<h2>chapter2</h2>
<p>this chapter explaines ba bla bla</p>

<h2>chapter3</h2>
<p>this chapter explaines ba bla bla</p>

<h2><a name="c4">chapter4</a></h2>
<p>this chapter explaines ba bla bla</p>

<h2>chapter5</h2>
<p>this chapter explaines ba bla bla</p>

<h2>chapter6</h2>
<p>this chapter explaines ba bla bla</p>

<h2>chapter7</h2>
<p>this chapter explaines ba bla bla</p>

<h2>chapter8</h2>
<p>this chapter explaines ba bla bla</p>

<h2>chapter9</h2>
<p>this chapter explaines ba bla bla</p>

<h2>chapter10</h2>
<p>this chapter explaines ba bla bla</p>

<h2>chapter11</h2>
<p>this chapter explaines ba bla bla</p>

<h2>chapter12</h2>
<p>this chapter explaines ba bla bla</p>

<h2>chapter13</h2>
<p>this chapter explaines ba bla bla</p>

<h2>chapter14</h2>
<p>this chapter explaines ba bla bla</p>

<h2>chapter15</h2>
<p>this chapter explaines ba bla bla</p>

<h2>chapter16</h2>
<p>this chapter explaines ba bla bla</p>

<h2>chapter17</h2>
<p>this chapter explaines ba bla bla</p>
</body>
</html>

Creating Mailto:link

<html>
<body>
<p>
this is a mail link:
<a href="mailto:someone@microsoft.com?subject=Hello%20again">Send mail</a>
</p>
<p>
<b>Note:</b>spaces between words shouls be replaced by %20 to <b>ensure</b>that the browser will display text proparly.
</p>
</body>
</html>

<html>
<body>
<p>
this is another mail to link:
<a href="mailto:someone@microsoft.com?cc=someoneelse@microsoft.com&bcc=someoneelse@microsoft.com&subject=summer%20party&body=you%20 are %20 invented%20to%20a%20big%20summer%20party!">send mail!</a>
<p>
</body>
</html>

Creating an Image link

<html>
<body>
<p> creating a link attached to an image:
<a href="defult.htm">
<img src="smiley.gif" alt="HTML tutorial" width="32" height="32"/>
</a>
</p>

<p> creating a link attached to an image:
<a href="defult.htm">
<img border="0" src="smiley.gif" alt="HTML tutorial" width="32" height="32"/>
</a>
</p>
</body>
</html>

No comments:

My Favorite Books

  • C and Data Structures by Ashok N. kamthane
  • Web Technologies by A. A. Puntambekar
  • Learn HTML and CSS with W3Schools
  • Learn JavaScript and Ajax with W3Schools
  • HTML5 Black Book: Covers Css3, Javascript,XML, XHTML, Ajax, PHP And Jquery
  • HTML5 Application Development Fundamentals: MTA Exam 98-375
  • .NET 4.0 Programming 6-In-1, Black Book
  • SQL Server 2008 R2 Black Book
  • Asp.net 4.0 Projects Covers: net 3.5 And .net 4.0 Codes, Black Book
  • UNIX Shell Programming 1 Edition by Yashavant Kanetkar
  • UNIX and Shell Programming 1 Edition by Richard F. Gilberg, Behrouz A. Forouzan
  • Computer Networks by Andrew S. Tanenbaum
  • Multiple Choice questions in computer science by Timothy J Williams