[英]Relative path in Script src and Link rel keeps resolving to root URL
我有一个位于http://localhost:8081/develop
的文档。
该index.html
,位于http://localhost:8081/develop/index.html
包含以下内容:
<html>
<head>
...
<link rel="stylesheet" href="./styles.min.css">
<script src="./bower_components/jquery/dist/jquery.js"></script>
<script src="./bower_components/moment/min/moment-with-locales.js"></script>
<script src="./bower_components/elessar/dist/elessar.js"></script>
<script src="./bower_components/EventSource/eventsource.js"></script>
...
</head>
<body>
...
</body>
</html>
所有文件都以./
开头,告诉浏览器应该在当前目录中搜索它们,例如: <script src="./bower_components/jquery/dist/jquery.js"></script>
应该可以解析进入http://localhost:8081/develop/bower_components/jquery/dist/jquery.js
。 很明显
但事实并非如此。 相反,它们被解析为http://localhost:8081/bower_components/jquery/dist/jquery.js
,在控制台中http://localhost:8081/bower_components/jquery/dist/jquery.js
大量错误。
如果在文件的开头而不是使用./
,则将发生相同的情况,而是删除第一个斜杠: <script src="bower_components/jquery/dist/jquery.js"></script>
也会解析为http://localhost:8081/bower_components/jquery/dist/jquery.js
。
这似乎是一个非常基本的问题,但我确实需要这些文件具有相对路径,并且这些路径能够按预期工作。 那为什么不呢?
原因可以在开头部分标记<base href="/">
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.