The A Link Tag in HTML
The A tag in HTML is used to create hyperlinks on a webpage. Clicking on this link tag will take you to another page elsewhere on the website or to another website on the Internet. The A link tag has several optional attributes like “accesskey”, which links a shortcut key on your keyboard to the link tag, or “type”, which specifies the MIME type of the link target. While you’ll rarely use these optional attributes, you will be using the ‘href” attribute of the link tag. The “href” attribute defines the target of the link -the address of the page you’re linking to.
Let’s write a simple “a” tag so you’ll see how it works:
<!DOCTYPE html> <html> <body> <a href="http://www.google.com">Open a Search Engine!</a> </body> </html>
Here, you can see that the “href” attribute has been specified as http://www.google.com. It will create a blue, underlined hyperlink to the Google search engine. Once you click on the link, it will become red, which shows its active status. An already-visited link is shown in purple.
Instead of using just plain text as the medium for the hyperlink, you can use an image as well. For example, if you had an image called “image1” on your webpage, it could act like a hyperlink:
<!DOCTYPE html> <html> <body> <a href="www.google.com><img src="image1.jpg" border="1"></a> </body> </html>
The browser will then search for a function called “openwindow ()” to execute within your program. What we’re doing is replicating the functionality of a normal button with the help of a hyperlink. The function to be executed will have to be written at the head of your program. You can do many things with it, that’s why. For example, you can get a new window to open when you click on a hyperlink within your webpage. Let’s write the code for that:
Once you’re written the code in the head section, create a hyperlink where you want it to appear on your webpage:
Now, when you click on the “Open a New Window” hyperlink, a new window will pop open in your browser. This window will have the dimensions 400 and 300 and it will be resizable. You will need to specify the web address of the window you’re trying to open, of course. In our example, we used the window “xyz.htm”.
You can also use an image with the href attribute. For example, if a user clicks on a small icon of an image, you can get a new window to pop open with the full-size version of that image. You can use the following code to get a new window to pop up if a user clicks on an image on your webpage:
If you have the full size version of an image on your webserver, you could get it to load in the new window.
This is a working program that uses the “location” attribute to retrieve and display the URL of the current open webpage.