网址哈希与Html基地标记 [英] Url Hash with Html Base Tag
本文介绍了网址哈希与Html基地标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
window.location.hash
当我为JavaScript动作使用链接时,我通常会这样做:
< a href =#>链接文字< / a>
这样,当有人在页面加载之前点击链接,没有什么可怕的事情发生。 b
$ b
Html Base Tag
在我目前的项目中,我使用这个相同的结构,但带有一个基本标签:
< html>
< head>
< base href =http://example.com//>
< / head>
< body>
< a href =#>连结文字< / a>
< / body>
< / html>
但是,如果网页网址为:
http://example.com/dir/page
点击链接导航到
http://example.com/#
而不是
http://示例。 com / dir / page#
如何解决这个问题?
解决方案
删除您的 base
标签或更改您的 href
属性完全合格。当你将 base
与 a
元素混合使用时,你正在观察的是预期行为。
window.location.hash
When using a link for a javascript action, I usually do something like this:
<a href="#">Link Text</a>
That way, when someone clicks the link before the page loads nothing terrible happens.
Html Base Tag
On my current project I use this same construct, but with a base tag:
<html>
<head>
<base href="http://example.com/" />
</head>
<body>
<a href="#">Link Text</a>
</body>
</html>
However, if the page url is:
http://example.com/dir/page
clicking the link navigates to
http://example.com/#
rather than
http://example.com/dir/page#
How can I fix this?
解决方案
Either remove your base
tag or change your href
attributes to be fully qualified. What you are observing is the intended behavior when you mix base
with a
elements.
这篇关于网址哈希与Html基地标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文