html base tag not working correctly

时光毁灭记忆、已成空白 提交于 2019-12-11 06:07:32

问题


I am using html base tag in head but not working very well.

This is my folder structure.

- BaseWebsite (Folder)
- - Root (Folder)
- - default.html
- - css (Folder)
- - js (Folder)
- - image (Folder)

in IIS, i create a new web site pointing to BaseWebsite and made Root an application.

This is my code in default.html

<html>
<head>

<link rel="stylesheet" type="text/css" href="css/site.css" />
<script language="javascript" src="js/site.js" type="text/javascript"></script>

</head>
<body>
<img src="image/site.jpg" />
.
.
.
</body>
</html>

When I run the page, css is there with the href="Root/css/site.css" but js and image are missing with the src starting js/site.js and image/site.jpg

So I put this after <head>

<base href="/Root/" />

Now, both js and image are showing but css is not showing as the href becomes href="/Root/Root/css/site.css"

Is it normal or how do I solve this? I can solve it by change href of css to /Root/css/site.css but there are a lot of places to change.


回答1:


In a base element, the href attribute must be an absolute URL, such as http://www.example.com/foo/bar/. A URL that begins with / (or .) is relative.

You need to fix the absolute URL or use some other technique, such as a server-side programming tool or a preprocessor.




回答2:


i dont know how behaves ISS, but try with dot:

<link rel="stylesheet" type="text/css" href="./css/site.css" />

i hope it helps

brief explanation: "./" starts where default.html is.

long explained here: What does "./" (dot slash) refer to in terms of an HTML file path location?



来源:https://stackoverflow.com/questions/17078826/html-base-tag-not-working-correctly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!