Saturday, July 25, 2015

13. HTML Text Links

 HTML Tutorial

A webpage can contain various links that take you directly to other pages and even specific parts of a given page. These links are known as hyperlinks.
Hyperlinks allow visitors to navigate between Web sites by clicking on words, phrases, and images. Thus you can create hyperlinks using text or images available on a webpage.
Note: I recommend to go through a short tutorial on Understanding URL

Linking Documents

A link is specified using HTML tag . This tag is called anchor tag and anything between the opening tag and the closing 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 tag.
 href="Document URL" ... attributes-list>Link Text

Example

Let's try following example which links http://www.tutorialspoint.com at your page:



</span><span class="pln">Hyperlink Example</span><span class="tag">
Click following link href="http://www.tutorialspoint.com" target="_self">Tutorials Point This will produce following result, where you can click on the link generated Tutorials Point to reach to the home page of Tutorials Point.
Click following link
Tutorials Point

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:
OptionDescription
_blankOpens the linked document in a new window or tab.
_selfOpens the linked document in the same frame.
_parentOpens the linked document in the parent frame.
_topOpens the linked document in the full body of the window.
targetframeOpens the linked document in a named targetframe.

Example

Try following example to understand basic difference in few options given for target attribute.



</span><span class="pln">Hyperlink Example</span><span class="tag">
 href="http://www.tutorialspoint.com/">
Click any of the following links href="/html/index.htm" target="_blank">Opens in New | href="/html/index.htm" target="_self">Opens in Self | href="/html/index.htm" target="_parent">Opens in Parent | href="/html/index.htm" target="_top">Opens in Body This will produce following result, where you can click on different links to understand the difference between various options given for target attribute.
Click any of the following links
Opens in New | Opens in Self | Opens in Parent | Opens in Body

Use 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 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

Following example makes use of tag to specify base URL and later we can use relative path to all the links instead of giving complete URL for every link.



</span><span class="pln">Hyperlink Example</span><span class="tag">
 href="http://www.tutorialspoint.com/">
Click following link href="/html/index.htm" target="_blank">HTML Tutorial This will produce following result, where you can click on the link generated HTML Tutorial to reach to the HTML tutorial.
Now given URL is being considered as .
Click following link
HTML Tutorial

Linking 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 tag as follows:

HTML Text Links name="top">
Second step is to create a hyperlink to link the document and place where you want to reach:
 href="/html/html_text_links.htm#top">Go to the Top
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.
Go to the Top

Setting Link Colors

You can set colors of your links, active links and visited links using link, alink and vlink attributes of tag.

Example

Save the following in test.htm and open it in any web browser to see how link, alink and vlink attributes work.



</span><span class="pln">Hyperlink Example</span><span class="tag">
 href="http://www.tutorialspoint.com/">
alink="#54A250" link="#040404" vlink="#F40633"> Click following link href="/html/index.htm" target="_blank" >HTML Tutorial This will produce following result. Just check color of the link before clicking on it, next check its color when you activate it and when the link has been visited.
Click following link
HTML Tutorial

Download 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:



</span><span class="pln">Hyperlink Example</span><span class="tag">
href="http://www.tutorialspoint.com/page.pdf">Download PDF File This will produce following link and will be used to download a file.

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, " );
while(read(FILE, $buffer, 100)){
   print("$buffer");
}
Note: For more detail on PERL CGI programs, go through tutorial PERL and CGI.

1 comments:

suman said...

thank you for nice information .
welookups html tutorial

Post a Comment

 
Designed by Kakada Akkarak Surakkiat
Technology: របៀប​ដំឡើង Windows 10 នៅ​លើ​កុំព្យូទ័រ!: អ្នកត្រូវដឹងឲ្យ ច្បាស់ពី Windows ដែលអ្នកយក ទៅដំឡើង ដោយសារមាន Windows ខ្លះមានការ crack រួច ឬខ្លះត្រូវការ Product key ភ្លាម និងខ្លះទៀត អាចត្រូវ skip កន្លែងវាយលេខ Product key បាន តែត្រូវ Activate តាមក្រោយ ទើបប្រើប្រាស់បាន។ Technology: ដំណោះ​ស្រាយ Error 80240020 នៅ​ពេល​តម្លើង Windows 10 Free តាម​រយៈ​ការ Upgrade : មាន បញ្ហាមួយចំនួន ទាក់ទងនឹង ការតម្លើង Windows 10 នេះផងដែរ ប៉ុន្តែបញ្ហានោះ កើតឡើង ទៅលើតែកុំព្យូទ័រ មួយចំនួនប៉ុណ្ណោះ គឺខណៈពេល ដែលអ្នក ប្រើប្រាស់ បានទាញយក Windows 10 ចប់ហើយ វាបាន បង្ហាញនូវ ផ្ទាំង error មួយ ដែលមានលេខ សំគាល់ error នោះគឺ 80240020។ ដូចនេះដើម្បី ដោះស្រាយ នូវបញ្ហា មួយនេះ សូមលោកអ្នក តាមដានអាន ជាមួយយើងខ្ញុំ ទាំងអស់គ្នា !!