adsense


Showing posts with label HTML 5 HYPER LINKS. Show all posts
Showing posts with label HTML 5 HYPER LINKS. Show all posts

Monday, 12 October 2015

HTML 5 HYPER LINKS PAGE 20


HTML 5 HYPER LINKS


HYPERLINKS 

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 <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.
<a href="Document URL" ... attributes-list>Link Text</a>
Example
Let's try following example which links http://www.onlionedu.blogspot.in at your page:
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
</head>
<body>
<p>Click following link</p>
<a href="http://www.onlionedu.blogspot.in" target="_self">Tutorials Point</a>
</body>
</html>
This will produce following result, where you can click on the link generated Tutorials Pointto reach to the home page of Tutorials Point.
Click following link

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
Try following example to understand basic difference in few options given for target attribute.
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
<base href="http://www.onlionedu.blogspot.in/">
</head>
<body>
<p>Click any of the following links</p>
<a href="/html/index.htm" target="_blank">Opens in New</a> |
<a href="/html/index.htm" target="_self">Opens in Self</a> |
<a href="/html/index.htm" target="_parent">Opens in Parent</a> |
<a href="/html/index.htm" target="_top">Opens in Body</a>
</body>
</html>
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 <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
Following example makes use of <base> tag to specify base URL and later we can use relative path to all the links instead of giving complete URL for every link.
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
<base href="http://www.onlionedu.blogspot.in/">
</head>
<body>
<p>Click following link</p>
<a href="/html/index.htm" target="_blank">HTML Tutorial</a>
</body>
</html>
This will produce following result, where you can click on the link generated HTML Tutorialto reach to the HTML tutorial.
Now given URL <a href="/html/index.htm" is being considered as <a href="http://www.onlionedu.blogspot.in/html/index.htm".
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 <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.
Go to the Top

Setting Link Colors

You can set colors of your links, active links and visited links using link, alink and vlinkattributes of <body> tag.
Example
Save the following in test.htm and open it in any web browser to see how link, alink andvlink attributes work.
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
<base href="http://www.onlionedu.blogspot.in/">
</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>
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:
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
</head>
<a href="http://www.onlionedu.blogspot.in/page.pdf">Download PDF File</a>
</body>
</html>
This will produce following link and will be used to download a file.

Download PDF 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, "<FileName" );
while(read(FILE, $buffer, 100)){
   print("$buffer");
}
We have seen how to create hypertext link using text and we also learnt how to use images in our webpages. Now we will learn how to use images to create hyperlinks.
Example
It's simple to use an image as hyperlink. We just need to use an image inside hyperlink at the place of text as shown below:
<!DOCTYPE html>
<html>
<head>
<title>Image Hyperlink Example</title>
</head>
<body>
<p>Click following link</p>
<a href="http://www.onlionedu.blogspot.in" target="_self"> 
   <img src="/images/logo.png" alt="Tutorials Point" border="0"/> 
</a>
</body>
</html>
This will produce following result, where you can click on the images to reach to the home page of Tutorials Point.
Click following link

This was the simplest way of creating hyperlinks using images. Next we will see how we can create Mouse-Sensitive Image Links.
Mouse-Sensitive Images
The HTML and XHTML standards provide a feature that lets you embed many different links inside a single image. You can create different links on the single image based on different coordinates available on the image. Once different are links attached to different coordinates, we can click different parts of the image to open target documents. Such mouse-sensitive images are known as image maps.
There are two ways to create image maps:
•	Sserver-side image maps - This is enabled by the ismap attribute of the <img> tag and requires access to a server and related image-map processing applications.
•	Client-side image maps - This is created with the usemap attribute of the <img> tag, along with corresponding <map> and <area> tags.
Server-Side Image Maps
Here you simply put your image inside a hyper link and use ismap attribute which makes it special image and when the user clicks some place within the image, the browser passes the coordinates of the mouse pointer along with the URL specified in the <a> tag to the web server. The server uses the mouse-pointer coordinates to determine which document to deliver back to the browser.
When ismap is used, the href attribute of the containing <a> tag must contain the URL of a server application like a cgi or PHP script etc. to process the incoming request based on the passed coordinates.
The coordinates of the mouse position are screen pixels counted from the upper-left corner of the image, beginning with (0,0). The coordinates, preceded by a question mark, are added to the end of the URL.
For example, if a user clicks 20 pixels over and 30 pixels down from the upper-left corner of the following image:
Click following link

Which has been generated by the following code snippet:
<!DOCTYPE html>
<html>
<head>
<title>ISMAP Hyperlink Example</title>
</head>
<body>
<p>Click following link</p>
<a href="/cgi-bin/ismap.cgi" target="_self"> 
   <img ismap src="/images/logo.png" alt="Tutorials Point" border="0"/> 
</a>
</body>
</html>
Then the browser sends the following search parameters to the web server which can be processed by ismap.cgi script or map file and you can link whatever documents you like to these coordinates:
/cgi-bin/ismap.cgi?20,30
This way you can assign different links to different coordinates of the image and when those coordinates are clicked, you can open corresponding linked document. To learn more about ismap attribute, you can check How to use Image ismap?
Note: You will learn CGI programming when you will study Perl programming. You can write your script to process these passed coordinates using PHP or any other script as well. For now let's concentrate on learning HTML and later you can revisit this section.
Client-Side Image Maps
Client side image maps are enabled by the usemap attribute of the <img /> tag and defined by special <map> and <area> extension tags.
The image that is going to form the map is inserted into the page using the <img /> tag as a normal image, except it carries an extra attribute called usemap. The value of the usemap attribute is the value which will be used in a <map> tag to link map and image tags. The <map> along with <area> tags define all the image coordinates and corresponding links.
The <area> tag inside the map tag, specifies the shape and the coordinates to define the boundaries of each clickable hotspot available on the image. Here's an example from the image map:
<!DOCTYPE html>
<html>
<head>
<title>USEMAP Hyperlink Example</title>
</head>
<body>
<p>Search and click the hotspot</p>
<img src=/images/html.gif alt="HTML Map" border="0" usemap="#html"/>
<!-- Create  Mappings -->
<map name="html">
   <area shape="circle" 
   coords="80,80,20" href="/css/index.htm" alt="CSS Link" target="_self" />
   <area shape="rect" 
   coords="5,5,40,40" alt="jQuery Link" href="/jquery/index.htm" target="_self" />
</map>
</body>
</html>
Its not difficult to put an HTML email link on your webpage but it can cause unnecessary spamming problem for your email account. There are people who can run programs to harvest these types of emails and later use them for spamming in various ways.
You can have another options to facilitate people to send you emails. One option could be to use HTML forms to collect user data and then use PHP or CGI script to send an email.
A simple example, check our Contact Us Form. We take user feedback using this form and then we are using one CGI program which is collecting this information and sending us email to one given email ID.
Note: You will learn about HTML Forms in HTML Forms and you will learn about CGI in our another tutorial Perl CGI Programming.
HTML Email Tag
HTML <a> tag provides you option to specifiy an email address to send an email. While using <a> tag as an email tag, you will use mailto:email address along with href attribute. Following is the syntax of using mailto instead of using http.
<a href= "mailto:abc@example.com">Send Email</a>
This code will generate following link which you can use to send email.
Send Email 
Now if a user clicks this link, it launches one Email Client ( like Lotus Notes, Outlook Express etc. ) installed on your user's computer. There is another risk to use this option to send email because if user do not have email client installed on their computer then it would not be possible to send email.
Default Settings
You can specify a default email subject and email body alongwith your email address. Following is the example to use default subject and body.
<a href="mailto:abc@example.com?subject=Feedback&body=Message">
Send Feedback
</a>