Firefox:我可以在 BASE 标记中使用相对路径吗?
我有一个小型网络项目,其中有很多页面和一个索引/目录文件。 toc 文件位于我项目的根目录下的 toc.html
中。这些页面分布在几个子目录中,并包含带有 iframe
的目录。
该项目不需要 Web 服务器,因此我可以在目录中创建 HTML 并在浏览器中浏览它。问题是,当 toc.html
中的 JavaScript 想要调用页面中的函数(违反同源策略)时,我遇到了 XSS 问题。
因此,我在标头中添加了 base
标记,并带有 toc.html
所在目录的相对 URL。这适用于 Konqueror,但在 Firefox 中,我必须使用绝对路径,否则目录甚至不会显示:( 这是一个示例:
<?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 甚至不会显示加载它,说它找不到 page/toc.html
是否有解决方法?我真的想避免导出中的绝对路径以使其在各处(本地和当我时)相同。稍后将其上传到网络服务器上)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 HTML4 中,
需要 绝对URI。然而,由于 HTML5 现在得到了广泛的支持,应该提到 HTML5
标签接受 URL,可以是绝对的也可以是相对的;这实际上意味着您现在可以使用相对路径而不是绝对 URI。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.