html里的base标签,用来设置当前页面的默认起始路径和默认打开目标。
用法如下:
<base href="url " target="location "/>。
问题出现在url 上。这个url 必须以“/”结尾,否则会产生错误。
比如:
有<base href="http://localhost/project/"/>,
页面后面有路径:image/logo.gif。
这个全路径就是http://localhost/project/image/logo.gif。
如果是路径/image/logo.gif.
这个全路径就市http://localhost/image/log.gif。
如果base标签写成<base href="http://localhost/project"/>,
那么不同浏览器有不同解释:
ie中,这个写法和上面第一种没有区别;
opera和firefox中,这个写法都会导致类似“image/logo.gif"这样的路径失效。
前两天写了个Javascript,开始在ie下,使用base标签没有问题。后来转到Opera,结果就出问题。断断续续调试了两个星期,才发现那个js文件根本没有引入近来。这才怀疑到base上来。
解决了。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/eastoneking/archive/2009/08/01/4399028.aspx
补充:
HTML元素 <base> 定义 元素说明 示例代码 This example sets the base URL of the document to a reference folder. Internet Explorer uses the base element to resolve the link to http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/href_2.asp. <HTML> 下面的例子表示,如在文档中指定了合法的 base 元素,则从文档中获取基础 URL;反之,返回 null。 <SCRIPT> 使用<base>标签最主要的原因,是为了确保文档中所有的相对URL都可以被分解成正确的文档地址,即使在文档本身被移动或重命名的情况下也可以正确解析。 Definition and Usage Differences Between HTML and XHTML In XHTML the <base> tag must be properly closed. Tips and Notes Example Now we insert the <base> tag, which specifies a base URL for all of the links in a page, in the head section of a page: <head> When inserting images on the page in the example above, we just have to specify the relative address, and the browser will look for that file using the full URL, "http://www.w3schools.com/images/smile.gif": Required Attributes
Optional Attributes
|
属性 | 值 | 描述 | DTD |
---|---|---|---|
target | _blank _parent _self _top | Where to open all the links on the page. This attribute can be overridden by using the target attribute in each link. 页面中所有连接的打开方式。如果每个连接使用了target属性那么base的target属性就无效了
| TF |
Standard Attributes and Events
标准属性以及事件
NONE
无
Try-It-Yourself Demos
演示
One target for all links
How to use the <base> tag to let all the links on a page have the same target.
怎样使用<base>标签来让所有连接使用同一个target
struts标记 <html:base>
<html:base/>不是必须的。
它将在输出的html文件的head中添加进类似<base href="http://server:port/requestURI"/>
的东东。
浏览器通过base标签来把当前HTML文件中所有的相对URL转换成绝对URL。
举例如下:
MyView.jsp的内容是
...
<html:base/>
</head>
<body>
<a href="../anotherPage.html" id="aLink">相对URL</a>
</body>
...
我们通过在浏览器中输入http://server:port/context/subpath/MyServlet
MyServlet的View即是MyView.jsp。
那么浏览器将收到如下的内容:
...
<base href="http://server:port/context/subpath/MyServlet" />
</head>
<body>
<a href="../anotherPage.html" id="aLink">相对URL</a>
</body>
...
这样当我们点击相对URL时,浏览器将把base与a通过某种方式连接起来得到
一个绝对的URL,从而把网页转到这个绝对的URL上去.
就上例来说,浏览器得到的连接起来后的URL是:
http://server:port/context/subpath/../anotherPage.html
正常化后成:
http://server:port/context/anotherPage.html
于是最终转到的页面就是正常化后的绝对URL了.
一言以蔽之:
浏览器通过Base标签来把当前文档中的相对URL转成绝对的URL.
如果MyView.jsp的内容是
...
<base href="http://www.163.com/news/index.html"/>
</head>
<body>
<a href="../anotherPage.html" id="aLink">相对URL</a>
</body>
...