How does the HTML base tag work? Summary of usage of HTML base tags

Source: Internet
Author: User
This article mainly describes the use of HTML base tags, as well as the specific use of HTML base tag instance parsing, then let's look at this article together

First, let's start with the HTML base tag:

The <base> tab specifies the default address or default destination for all links on the page.

Typically, the browser extracts the corresponding element from the URL of the current document to fill in the whitespace in the relative URL.

Using <base> tags can change this. The browser will then no longer use the URL of the current document and use the specified base URL to resolve all relative URLs. This includes URLs in the <a>, , <link>, <form> tags.

Note the:<base> tag must be inside the head element.

There is also an introduction to the HTML Base tag properties:

Let's take a look at the example:


Do you know the effect of this code? Now let's look at the actual effect in the browser:

Because I did not enter the correct picture path, so the display is this effect, you can enter the correct path to see.

Now let's look at the use of the HTML base tag:

The base tag is a base link tag and is a single tag. The default value of the parameter used to change all the link tags in the file. It can only be applied between tags

All relative paths on your Web page will be preceded by the address that the base link points to.

base element to specify the base URL for all links in the page

We can use the href attribute in the <base> tag to set all the "relative base URLs".

This is the JSP-side code

The <base> tags in the HTML file are used:

The code is as follows:

<%string path = Request.getcontextpath ();//Get the Project full path (assuming your project is called MyWork, then the address you get is http://localhost:12138/myhtml/): String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";//Will " Project path BasePath "into PageContext%>

When we go through the JSP code above, we can see in the browser the HTML code that he returns to the client:

After executing the above JSP, the HTML code returned is as follows:


We can see the HTML code returned by the JSP, including the <base href= "http://localhost:12138/myhtml/" > Content.

That is, in this HTML file, all "relative links (for example: <a href=" jsp/login.jsp ">)", are relative to the base path (i.e.: http://localhost:12138/myhtml/)

Well, this is the introduction of the HTML base tag usage (want to see more HTML knowledge, Welcome to topic.alibabacloud.comhtml Video tutorial), there are questions can be asked below.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.