URL中有多个哈希标志

编程入门 行业动态 更新时间:2024-10-27 18:19:56
本文介绍了URL中有多个哈希标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

或许你称它为尖锐 - #符号。

Or maybe you call it "sharp" - the # symbol.

我遇到过一个实例,其中#!和#在一个URL中同时使用。通过阅读其他文章,包括RFC,我无法理解这是否是合法的组合。当遇到这样的页面时,Mozilla浏览器(在这种情况下为Iceweasel)将URL显示为2#,而Chrome只显示一个,但不久之后就会死亡(包含页面的选项卡变得无响应并崩溃 - 但可能无法连接) 。

I've came across one instance, where #! and # used simultaneously in a single URL. From reading other articles, including RFC, I can't understand whether that is a legal combination or not. When encountering such page Mozilla browser (Iceweasel in this case) displays the URL as having 2 #'s, while Chrome displays only one, but dies shortly afterwards (the tab containing the page becomes unresponsive and crashes - but it may not be connected).

现在,我的问题是,在一个URL中同时使用它们是合法的还是冗余的(应该规范化),还是仅仅是一个bug在Mozilla浏览器中?所以,假设我正在制作一个AJAX请求,或试图浏览浏览器历史记录 - 如果我遇到这种情况,该怎么办?

Now, my question is, is it legal to have both in one URL, is it maybe legal and redundant (should be normalized), or is it just a bug in Mozilla browser? So, suppose I'm making an AJAX request, or trying to navigate the browser history - what should I do, if I encounter this situation?

RFC-3986: tools.ietf/html/rfc3986#section-3.4 ,应该澄清一下......以防万一。

RFC-3986: tools.ietf/html/rfc3986#section-3.4 , which should be clarifying it... just in case.

此外: developers.google/webmasters/ajax-crawling/docs/specification Google抓取工具如何查看内容。

Also: developers.google/webmasters/ajax-crawling/docs/specification how Google crawlers see things.

推荐答案

片段的格式只允许斜杠,问号和 pchar s。如果你查找RFC,你会发现哈希标记不是有效的 pchar 。

The format for a fragment only allows slashes, question marks, and pchars. If you look up the RFC, you'll see that the hash mark is not a valid pchar.

但是浏览器会尽量通过处理重复哈希来读取无效的URL,就像它们被转义一样,你可以通过检查 window.location.hash 的值来看到(在IE,Firefox和Chrome中

However, browsers will try their best to read non-valid URLs by treating repeat hashes as though they are escaped, as you can see by checking the value of window.location.hash (in IE, Firefox, and Chrome) for

www.example/hey#foo#bar

这与 window.location.hash 相同

www.example/hey#foo%23bar

更多推荐

URL中有多个哈希标志

本文发布于:2023-10-23 04:19:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519762.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   中有   标志   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!