Why base tag does not work for relative paths?(为什么基本标签不适用于相对路径?)
问题描述
我在页面的 <head>
部分有一个 <base>
标记,如下所示:
I have a <base>
tag as below in <head>
section of the page:
<base href="http://localhost/framework">
下面是一个相对的脚本(当然在<base>
之后):
And a script as below which is relative (of course after <base>
):
<script src="L2Fzc2V0cy9qcXVlcnktMS43LjEubWluLmpz">
但是当我从 firebug 打开 jQuery 时,它显示:
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="aHR0cDovL2xvY2FsaG9zdC9mcmFtZXdvcmsvYXNzZXRzL2pxdWVyeS0xLjcuMS5taW4uanM=">
我到处寻找答案,但看来我的工作做得对!那么问题出在哪里?
I looked for an answer everywhere, but it seems I'm doing my job right! So what is the problem?
推荐答案
/assets/jquery-1.7.1.min.js
不是相对的而是绝对的*,/
即使使用 base
标记也将其带到根目录.
/assets/jquery-1.7.1.min.js
is not relative but absolute*, the /
takes it to the root even with a base
tag.
如果您删除该 /
,它应该使其相对于当前路径,当 base
标记存在时,该路径将是 http://本地主机/框架/
.
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/
.
注意:您还需要在 href
的末尾添加一个尾随 /
,以表明它是一个文件夹.
Note: You will also need to add a trailing /
to the end of the href
, to indicate that it's a folder.
完整的工作示例:
<!doctype html>
<html>
<head>
<base href="/test/" />
<script src="YXNzZXRzL3Rlc3QuanM="></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.
这篇关于为什么基本标签不适用于相对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么基本标签不适用于相对路径?


- Flexslider 箭头未正确显示 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 400或500级别的HTTP响应 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01