在 URL 中使用多个片段标识符
我想知道是否可以在 url 中使用多个片段标识符,有点像这样: http://example.com/videos/index.html#videos#video_2
我在我的index.html 页面上使用jQuery Tools 选项卡系统以及历史记录插件。此页面的“视频”选项卡上有一个 Flash 视频播放器和视频列表。单击视频缩略图会将文件加载到播放器中。
我希望访问者不仅能够为 #videos 选项卡添加书签,还能够为特定视频添加书签。
我认为 URL 中包含两个片段标识符是实现此目的的方法是完全错误的吗?
I was wondering whether I can use multiple fragment identifiers in a url, sort of like this:http://example.com/videos/index.html#videos#video_2
I'm using jQuery Tools tabbing system on my index.html page, with the history plugin. This page's "Videos" tab has a flash video player and list of videos on it. Clicking on a video thumbnail loads the file into the player.
I would like a visitor to be able to bookmark not just the #videos tab, but also a specific video.
Am I going about it totally wrong to think having two fragment identifiers in the URL would be the way to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我很确定双锚链接是不可能的!
您可以在 URL 的查询字符串中放置指向正确选项卡和视频的指针(例如 mysite.com/videos/index.html?tab=video&video=2),然后在 JavaScript 中解析它。然后可以将其添加为书签。
但是,您是否不能坚持使用原始模型(使用单个 # 锚链接),然后简单地使用 JavaScript 查找该标签所在的选项卡,从而显示正确的选项卡?
I'm pretty sure that a double anchor link is impossible!
You could put a pointer to the correct tab and video in the query string of the url (e.g. mysite.com/videos/index.html?tab=video&video=2) and then parse this in JavaScript. This can then be bookmarked.
However couldn't you stick with the original model (using a single # anchor link) and then simply use JavaScript to find which tab that tag is in, and therefore show the correct tab?
不可以,您不能在一个 URL 中使用多个主题标签。哈希字符后面的标识符指向页面上的书签锚点,并且只能转到一个锚点,不能同时转到两个锚点。
如果您为视频添加书签,很自然的情况是 URL 会指向该视频,并且如果您需要在页面中显示特定选项卡,您应该拥有能够识别视频锚点并显示正确选项卡的代码。
No, you can't use multiple hashtags in an URL. The identifier after the hash characters leads to a bookmark anchor on the page, and you can only go to one anchor, you can't go to two anchors at the same time.
If you are bookmarking a video, the natural thing would be that the URL leads to the video, and if you need to show a specific tab in the page you should have code that recognises the video anchor and shows the correct tab.
解析
#
后面的URL片段的正则表达式是这样的:表示每个字符都可以传递。所以,
选择这两种方法之一:
例如:http://domain.com/app#first%23second
第一个很简单,但可能无法在您的特定应用程序中实现。
请参阅此文档以确保
#<之后的有效字符/代码>。
The regular expression to parse URL fragment after
#
is like this:It means that every character could be passed. So,
choose one of these two approaches:
ex: http://domain.com/app#first%23second
the first is easy but may not be implementable in your specific app.
see this doc to ensure about valid characters after
#
.一个简单的方法是使用这样的链接:
然后解析哈希以获取视频的 ID:
您还可以收听 "hashchange" 事件,以防万一有人在您的网页上复制/粘贴特定视频的 URL(例如,不同的哈希值):
A simple way would be to use a link like this:
Then parse the hash to get the ID of the video:
You could also listen to the "hashchange" event, just in case someone copy/pastes a URL for a specific video while already on your web page (e.g. with a different hash):