firefox哈希锚点url问题
我在页面上有一个表单,我正在处理它,并且(因为它已经下降了很多),如果出现错误,我会在 url 后面附加注释
show?comments=2#track_1
=2 位,这是对哪个字段出错的反馈,track_1 是我的表单所在的 div 的 id。这在 IE(至少 8)中效果很好,但在 Firefox 中,页面只是位于顶部,而不会跳到相关部分。
奇怪的是,当我选择 URL 并在地址栏中按下 Enter 时(即当我手动转到该地址时,而不是由表单的验证反馈生成该地址时),它在 Firefox 中工作!
有人对可能发生的事情有任何想法吗?
编辑
注意,只有在关闭 javascript 的情况下才会发生这种情况(尽管这正是我需要它工作的时候!)
I have a form on a page, that I'm working on, and (as it's quite a way down), if there's an error, I'm appending the url with
show?comments=2#track_1
where the comments=2 bit is feedback on which field went wrong, and track_1 is the the id of the div in which my form is sitting. This works great in IE (8 at least), but in firefox, the page just sits at the top, without jumping down to the relevant section.
Strangely enough, when I select the URL and push enter in the address bar (i.e. when I go to the address manually, instead of it being generated by the form's validation feedback) it works in firefox!
Anyone have any ideas on what could be going on?
EDIT
n.b. this is happening only with javascript turned off (though this is precisely when I need it to work!)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您的问题听起来像是一个已知的错误。在此处投票。
Your problem sounds like a known bug. Upvote it here.
如果页面中有自动对焦功能,这可能就是问题的原因。尝试取消自动对焦并进行测试。
如果是这个原因,请通过此链接对 mozilla 中的错误进行投票。
If you have an autofocus in the page, this can be the reason for the problem. Try removing the autofocus and test.
If it is the reason, upvote the bug in mozilla through this link.
使用#号的正确方式,这不是通过ID!
您必须使用锚点来命名该位置,如下所示:
Use the correct way of the #-sign, this is not by ID!
You have to name the position with an anchor like this:
将其添加到 JavaScript 中以更正视图,更改 YOUR_ANCHOR,作为有问题的锚点的名称。
这应该会重置 Firefox 问题。
Add this to the javascript to correct the view, change YOUR_ANCHOR, for the name of the anchor with issues.
That should reset the firefox issue.
如果您将 jQuery 与 smoothScroll 一起使用,则放置在所有其他 javascript 之后的以下脚本将起作用。您可以通过 http://cafedethaireno.net/index.php#togo_menu 检查它在 Firefox 中的运行情况
希望这有帮助,我使用固定的标题导航来偏移顶部位置,但可以轻松地操纵代码以适应。
If you're using jQuery with smoothScroll, the following script placed after all other javascript will work. You can check it working in Firefox at http://cafedethaireno.net/index.php#togo_menu
Hope this helps, I'm using a fixed header navigation to offset the top position, but the code can easily be manipulated to suit.
对我来说,这个问题是通过删除非字母数字字符(包括空格)来解决的,例如仅使用 -_ 的双点(也是网址编码的 %3A)。作为分隔符。
与您的问题并不真正相关,但也许对其他人而言:
For me this problem was solved by removing non alphanumeric characters (including spaces) like double point (also the url-encoded %3A) with the only use of -_. as separators.
not really related to your issue, but maybe for others: