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).
The base URL is the location of the current document by default, but it can be overridden by the 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/”.
You must use absolute paths when linking to another Website, but you can also use absolute paths within your own website.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With