如何让IE支持带有相对href的html基本标签?例如:` `
我知道根据规范,base
的 href
应该是绝对 URI。
href = uri [CT]
This attribute specifies an absolute URI that acts as the base URI for resolving relative URIs.
但是firefox和chrome支持相对URI,例如../../
,这对于我当前的项目非常重要。对于我的项目,除了“相对基本 href”之外,我没有找到更好的解决方案。
IE 是否有任何 hacks 或 workgrounds 可以让它支持相对 URI?我的网页现在在 Firefox 和 Chrome 中运行良好,但它必须支持 IE。
I know according to the spec, the href
of base
should be a absolute URI.
href = uri [CT]
This attribute specifies an absolute URI that acts as the base URI for resolving relative URIs.
But firefox and chrome support relative URIs, e.g. ../../
, which is very important of my current project. I don't find a better solution other than "relative base href" for my project.
Is there any hacks or workgrounds for IE to let it support relative URIs? My web pages works well in firefox and chrome now, but it has to support IE.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用此函数将您的 URL 转换为绝对 URL:
您可以使用
示例 http://jsfiddle.net/tEpkx/1/
除了您还必须检测浏览器,并且仅针对 IE 运行它。其他浏览器将自动通过
base
标记的 href 更新 window.location,此代码片段将再次更改它。所以写成ps:
是单个标签,不需要结束标签。更新以包含端口号(如果已设置)。
Use this function to convert your URL to the absolute:
You could use
Example http://jsfiddle.net/tEpkx/1/
Except that you have to detect the browser, too, and run it only for IE. Other browsers will get window.location updated by the href of the
base
tag automatically and this code snippet will change it again. So write it asps:
<base />
is a single tag, it does not require the closing one.Updated to include the port number if it is set.