Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html <base> tag referring to local folder

Tags:

html

I'm trying to set a local site-root using the base tag. The following code isn't working. Am I doing something wrong? How do I set the mysite folder as base?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <base href="file:///home/me/mysite"></base>
      <title> Asset Take On Process </title>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 
      <link rel="stylesheet" type="text/css" href="/css/main.css" />
    </head>
    <body>
      some stuff
    </body>
  </html>

The site folder structure is

mysite
   |___css
   |___img
   |___js

and so on..

When I load the web-page it doesn't see the main.css in the css folder at all.

like image 441
Tahnoon Pasha Avatar asked Aug 26 '13 09:08

Tahnoon Pasha


People also ask

Where should a base href be placed?

The <base> tag must have either an href or a target attribute present, or both. There can only be one single <base> element in a document, and it must be inside the <head> element.

How do you use a base tag?

The HTML base tag is used to specify a base URI, or URL, for relative links. This URL will be the base URL for every link on the page and will be prefixed before each of them. For example, if the URL specified by the base tag is “www.xyz.com” and then every other URL on the page will be prefixed by, “www.xyz.com/”.

What is the use of base href?

The href attribute specifies the base URL for all relative URLs on a page.


1 Answers

If you remove that /, it should make it relative off the current path, which, when a base tag is present would be

http://localhost/website/.

You will also need to add a trailing / to the end of the href, to indicate that it's a folder.

Full working example:

<!doctype html>
<html>
<head>
<base href="/test/" />
<script src="assets/test.js"></script>
<body>
hi
</body>
</html>
  • Actually depending on who you ask, it's still relative since it is relative off the current domain. But I prefer to call this absolute since it's signifying the path is from the root, based on the current domain. Although, I guess technically that makes it relative in the grand scheme of things, and absolute only in terms of the current domain. Whatever.

kindly refer this link

http://social.msdn.microsoft.com/Forums/ie/en-US/c51bb8b9-40ab-437b-a125-88b660f3e1ca/ie8-base-tag-issues

like image 181
backtrack Avatar answered Oct 12 '22 01:10

backtrack