Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
545 views
in Technique[技术] by (71.8m points)

html - How to override <base> tag without removing the tag itself?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...