Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox: Can I use a relative path in the BASE tag?

I have a little web project where I have many pages and an index/ToC file. The toc file is at the root of my project in toc.html. The pages are spread over a couple of subdirectories and include the toc with an iframe.

The project doesn't need a web server, so I can create the HTML in a directory and browse it in my browser. The problem is that I'm running into XSS issues when JavaScript from the toc.html wants to call a function in a page (violation of the same origin policy).

So I added base tags in the header with a relative URL to the directory in which toc.html. This works for Konqueror but in Firefox, I have to use absolute paths or the toc won't even display :( Here is an example:

<?xml version='1.0' encoding='utf-8' ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="../" target="_top" />
<title>Project 1</title>
</head>
<body>
<iframe class="toc" frameborder="0" src="toc.html">
</iframe>
</body>
</html>

This is file is in a subdirectory page. Firefox won't even load it, saying that it can't find page/toc.html.

Is there a workaround? I would really like to avoid absolute paths in my export to keep it the same everywhere (locally and when I upload it on the web server later).

like image 994
Aaron Digulla Avatar asked Dec 18 '09 09:12

Aaron Digulla


People also ask

Which of the following tags can be used to override the base URI method?

The base URL is the location of the current document by default, but it can be overridden by the base tag.

What is the purpose of 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/”.

Which kind of path do you use for external links?

You must use absolute paths when linking to another Website, but you can also use absolute paths within your own website.

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.


1 Answers

In HTML4, <base> needs an absolute URI. However, since HTML5 now has widespread support, it should be mentioned that the HTML5 <base> tag accepts an URL, which can be either absolute or relative; this effectively means that you can now use a relative path instead of an absolute URI.

like image 115
zneak Avatar answered Sep 25 '22 22:09

zneak