如何覆盖< base>标签不删除标签本身? [英] How to override <base> tag without removing the tag itself?

查看:87
本文介绍了如何覆盖< base>标签不删除标签本身?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图添加一些散列链接(以内容表的格式,以便于网页导航)到< base> 标记。

现在显然由于基本标记,每个其他相对标记都将相对于基本标记href。为了让我使用指向特定页面的不同部分的链接创建此内部表格,我需要获取默认URL(在基本标记生效之前),以便内部链接可以正常工作。



有没有办法避开基本标签并完成这项工作?

解决方案

base 标记的效果对文档是全局的,并且是覆盖< base href =...效果的唯一方法。 > 是使用绝对URL。



您可以使用 window.location in JavaScript来获取页面本身的URL,以防文档通过HTTP检索。您可以使用它来构建绝对URL。



现在通常不需要 base 标记。使用服务器端技术可以让您从一个或多个基地址构建地址,这样更好。所以很可能最好的办法是摆脱标签。


I'm trying to add some hash links (in the format of a content table, to be able to facilitate webpage navigation) to this site in which a <base> tag is used.

Now obviously due to the base tag, every other relative tag will be relative to the base tag href. In order for me to create this internal content table with the links pointing to different parts of the specific page, I need to get the default URL (before base tag is in effect) so the internal links can work properly.

Is there a way to do get around the base tag and accomplish this?

解决方案

The effect of the base tag is global to the document, and the only way to override the effect of <base href="..."> is to use absolute URLs.

You can use window.location in JavaScript to get the URL of the page itself, in case the document was retrieved via HTTP. And you could use it to construct absolute URLs.

The base tag is normally not needed these days. It is better to use server-side technologies that let you construct addresses from one or more base addresses. So quite possibly the best approach is to get rid of the tag.

这篇关于如何覆盖&lt; base&gt;标签不删除标签本身?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆