Jump to content

HTML base tag example


Kynikos

Recommended Posts

According to http://www.w3.org/TR/html5/document-metadata.html#the-base-element shouldn't the example in http://www.w3schools.com/tags/tag_base.asp have a base tag that points to the current page (not just the directory)? That would solve some problems with link fragments and query strings as outlined in e.g. http://stackoverflow.com/questions/1889076/is-it-recommended-to-use-the-base-html-tag

 

EDIT: This is a possible way I'd modify the example:

 <head><base href="http://www.w3schools.com/page.html'>http://www.w3schools.com/page.html" target="_blank"></head><body><img src="images/stickman.gif" width="24" height="39" alt="Stickman"><a href="http://www.w3schools.com">W3Schools</a></body> 
Edited by Kynikos
Link to comment
Share on other sites

It does look like the base tag should include the full URL to the current file, not to the current directory. That stack overflow discussion shows problems that can happen if only the directory is used.

Link to comment
Share on other sites

Your idea of setting the <base> tag to the exact same URL as the current page is redundant, it's the same as not using the <base> element at all. People use the <base> element when they want relative links to point to somewhere different. Usually, they have it pointing to a different directory.

Link to comment
Share on other sites

You make a point about the redundancy in that particular use case, but:

 

1) w3.org's specifications for HTML 5 http://www.w3.org/TR/html5/document-metadata#the-base-element and HTML 4.01 http://www.w3.org/TR/html401/struct/links.html#h-12.4 use full URLs in the examples, so currently I see an inconsistency. https://html.spec.whatwg.org/multipage/semantics.html#the-base-element uses full URLs too.

2) Suggesting to use a full URL (not necessarily to the current page) prevents the bugs reported in the stackoverflow discussion I linked in the OP; suggesting to use a directory URL has no advantage OTOH.

3) Having a base tag pointing to the current URL can be useful if a single document is saved locally, since all its relative links will still correctly point to the original domain. Also, always using a base tag could be a way to ensure crawling bots use the right URL for relative links.

Edited by Kynikos
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...