Anchor< a>标签不工作在铬时使用# [英] Anchor <a> tags not working in chrome when using #
本文介绍了Anchor< a>标签不工作在铬时使用#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我在我的网页上使用的代码, $ b
Here is the code I am using on my page,
<li><a href="/explore/#Sound">Sound</a></li>
(在所有页面上显示的菜单中)
(in a menu which appears on all pages)
<a id="Sound"><a>
(在我想链接的页面上)
(on the page where i want to link to)
我曾尝试使用ID为标签添加内容。但只有在Chrome浏览器不会向下滚动到标签。这些锚点在IE和FF
中有效?有什么想法?
I have tried adding content to the tags with an id. But only in chrome the browser will not scroll down to the tag. These anchors work in IE&FF Any ideas?
推荐答案
原来这是某些版本的chrome中的一个bug ,为任何需要它的人发布解决方法! :)
Turns out this was a bug in certain versions of chrome, posting workaround for anyone who needs it! :)
$(document).ready(function () {
var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
if (window.location.hash && isChrome) {
setTimeout(function () {
var hash = window.location.hash;
window.location.hash = "";
window.location.hash = hash;
}, 300);
}
});
这篇关于Anchor< a>标签不工作在铬时使用#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文