Jump to content
Kynikos

HTML base tag example

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

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...