是双正斜杠的URL散列片段确定 [英] Are double forward slashes ok in URL hash fragment

查看:133
本文介绍了是双正斜杠的URL散列片段确定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在建立从表单的JavaScript片段串并window.location.hash设置。如果用户离开表单输入空白生成的URL可以是

I am building the fragment string in javascript from a form and setting with window.location.hash. If a user leaves a form input blank the resulting URL can be

example.com/#search/cars//blue//mazda

请注意在 //

如果说是进入它的价格会

If say the price was entered it would be

 example.com/#search/cars/20000/blue//mazda

现在这工作正常。它是不好的做法?

Now this works fine. Is it bad practice?

推荐答案

我觉得 pushState的和其他历史API方法都这么初生的标准还没有进化。至于打开重新利用的新的Web井号最近W3工作一>:

I think that pushState and the other History API methods are so nascent that standards haven't yet evolved. As opens a recent W3 work on Repurposing the Hash Sign for the New Web:

在一个URI的哈希符号(#)原本是用来引进一个静态
  片段标识符,但最近它正在更多的使用
  因为它是由设置和跨$ P $由JavaScript的Web PTED复杂的方式
  应用程序。

The Hash sign (#) in a URI was originally used to introduce a static "fragment identifier", but recently it is being used in many more complex ways as it is set by and interpreted by JavaScript in Web applications.

这可能违反正常行为的路径用双斜线但散列片段可以是任意的字符串。做一个的typeof ,你会发现它只是一个普通的字符串。这不是标准,因此可能会疏远典型的用户体验。 code明智的,不过,我觉得你可以随时给你双斜线,斜线三倍,或其他任何东西。

It might violate normal behavior to use double slashes in the pathname but the hash fragment can be any arbitrary string. Do a typeof and you'll see it's just a normal string. It's not standard and therefore might alienate the typical user experience. Code wise, however, I think you can feel free to you double slashes, triple slashes, or anything else.

有一点要记住的是,转义字符 window.location.hash 属性读取时都去codeD。

One thing to keep in mind is that escaped characters are decoded when read from the window.location.hash property.

这篇关于是双正斜杠的URL散列片段确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆