HTML Text Links
Linking Documents
A link is specified using HTML tag <a>. This tag is called anchor tag and anything between the opening <a> tag and the closing </a> tag becomes part of the link and a user can click that part to reach to the linked document. Following is the simple syntax to use <a> tag.
EXAMPLE
<html>
<head>
<title>Hyperlink Example</title>
</head>
<body>
<p>Click following link</p>
<ahref="elearningwebdesigning.blogspot.com" target="_self">Tutorials Point</a>
</body>
</html>
RESULTS
Click following link
<a href="Document URL" ... attributes-list>Link Text</a
The Target Attribute
We have used target attribute in our previous example. This attribute is used to specify the location where linked document is opened. Following are possible options:
Option | Description |
---|---|
_blank | Opens the linked document in a new window or tab. |
_self | Opens the linked document in the same frame. |
_parent | Opens the linked document in the parent frame. |
_top | Opens the linked document in the full body of the window. |
targetframe | Opens the linked document in a named targetframe. |
EXAMPLE
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
<base href="elearningwebdesigning.blogspot.com/">
</head>
<body>
<p>Click any of the following links</p>
<ahref="/html/index.htm" target="_blank">Opens in New</a> |
<ahref="/html/index.htm" target="_self">Opens in Self</a> |
<ahref="/html/index.htm" target="_parent">Opens in Parent</a> |
<ahref="/html/index.htm" target="_top">Opens in Body</a>
</body>
</html>
RESULTS
Click any of the following linksUse of Base Path
When you link HTML documents related to the same website, it is not required to give a complete URL for every link. You can get rid of it if you use <base> tag in your HTML document header. This tag is used to give a base path for all the links. So your browser will concatenate given relative path to this base path and will make a complete URL.
EXAMPLE
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
<base href="https://www.tutorialspoint.com/">
</head>
<body>
<p>Click following link</p>
<ahref="/html/index.htm" target="_blank">HTML Tutorial</a>
</body>
</html>
RESULTS
Click following linkLinking to a Page Section
You can create a link to a particular section of a given webpage by using name attribute. This is a two step process.
First create a link to the place where you want to reach with-in a webpage and name it using <a...> tag as follows:
<h1>HTML Text Links <a name="top"></a></h1>
Second step is to create a hyperlink to link the document and place where you want to reach:
<a href="/html/html_text_links.htm#top">Go to the Top</a>
This will produce following link, where you can click on the link generated Go to the Top to reach to the top of the HTML Text Link tutorial.
Setting Link Colors
You can set colors of your links, active links and visited links using link, alink and vlink attributes of <body> tag.
EXAMPLE
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
<base href="elearningwebdesigning.blogspot.com/">
</head>
<body alink="#54A250" link="#040404" vlink="#F40633">
<p>Click following link</p>
<a href="/html/index.htm" target="_blank" >HTML Tutorial</a>
</body>
</html>
RESULTS
Click following linkDownload Links
You can create text link to make your PDF, or DOC or ZIP files downloadable. This is very simple, you just need to give complete URL of the downloadable file as follows:
EXAMPLE
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
</head>
<a href="elearningwebdesigning.blogspot.com">Download PDF File</a>
</body>
</html>
RESULTS
File Download Dialog Box
Sometimes it is desired that you want to give an option where a user will click a link and it will pop up a "File Download" box to the user in stead of displaying actual content. This is very easy and can be achieved using an HTTP header in your HTTP response.
For example, if you want make a FileName file downloadable from a given link then its syntax will be as follows.
#!/usr/bin/perl # Addtional HTTP Header print "Content-Type:application/octet-stream; name=\"FileName\"\r\n"; print "Content-Disposition: attachment; filename=\"FileName\"\r\n\n"; # Open the target file and list down its content as follows open( FILE, "<FileName" ); while(read(FILE, $buffer, 100)){ print("$buffer"); }
Comments
Post a Comment