为什么基地标签不适用于相对路径? [英] why base tag does not work for relative paths?
问题描述
我在页面的头部有一个BASE标签:
< base href =http:/ /本地主机/框架>
以下是相对的脚本(当然是基本标记之后):
< script src =/ assets / jquery-1.7.1.min.js>
但是,当我从萤火虫中打开jQuery时,它显示:
<!DOCTYPE HTML PUBLIC - // IETF // DTD HTML 2.0 // EN>
< html>< head>
< title> 404未找到< / title>
< / head>< body>
Blah Blah Blah ....
当我使用下面的链接时,虽然:
< script src =http://localhost/framework/assets/jquery-1.7.1.min.js >
我到处寻找答案,但看起来我正在做我的工作!那么问题是什么?
/assets/jquery-1.7.1.min.js
不是相对而是绝对的*, /
即使使用 base
如果你删除 /
,它应该使它与当前路径相对,当 base
标记存在于 http:// localhost / framework /
。
您还需要在 href
的末尾添加尾随 /
,以指示
完整的工作示例: !doctype html>
< html>
< head>
< base href =/ test //>
< script src =assets / test.js>< / script>
< body>
hi
< / body>
< / html>
*
其实取决于您问的是谁,它仍然是相对的,因为它与当前域相对。但我更愿意称之为绝对的,因为它表示路径来自根目录,基于当前域。虽然,我想在技术上,这使得它在事物的宏伟计划中是相对的,绝对只是在当前领域方面。无论如何。
I have a BASE tag as below in head section of the page:
<base href="http://localhost/framework">
And a script as below which is relative (of course after base tag):
<script src="/assets/jquery-1.7.1.min.js">
But when I open jQuery from firebug it shows:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
Blah Blah Blah....
When I use the below link it's OK though:
<script src="http://localhost/framework/assets/jquery-1.7.1.min.js">
I looked for answer everywhere, but it seems I'm doing my job right! So what is the problem?
/assets/jquery-1.7.1.min.js
is not relative but absolute*, the /
takes it to the root even with a base
tag.
If you remove that /
, it should make it relative off the current path, which, when a base
tag is present would be http://localhost/framework/
.
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.
这篇关于为什么基地标签不适用于相对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!