9

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?

7
  • Do you simply want the bookmark to jump to a specific place on the page? Or do you actually want to load the correct video when they open the link? Commented Feb 11, 2011 at 11:40
  • A hashtag is a means of indicating that a term should be hyperlinked to a search engine on social media networks. It gets the name because it it uses a hash character to prefix it. Please don’t confuse other uses of the hash character with hashtags. Commented Sep 12, 2014 at 7:05
  • 1
    This question is similar to: Multiple hash signs in URL. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Jun 29 at 23:31
  • 1
    Yes, I know that (I was processing your flag—probably— when I saw it). But the point is "why flag a 2011 post as duplicate of a 2012 post?" (especially since, seconds later, you also flagged the 2012 post as a duplicate of 2011 post. I mean, if both flags lead to deletion, we loose both message (sure, there are probably other duplicate of it. But strictly speaking, we don't know that. And there are, they should be the one used for the flag. Now you have been around longer, and I confess I am not very well versed of what the habits are. So maybe that is the correct way. But I find it strange) Commented Jul 2 at 17:58
  • 1
    @chrslg, I believe that I forgot which post I was on. Indeed, flagging the eldest (or most relevant) is usually better than flagging all duplicates on both sides. Commented Jul 2 at 21:29

4 Answers 4

6

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?

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

3

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:

  1. convert all hashes after the first one to '%23'. also you need to do this ( converting to %HEX eq.) for all non acceptable or reserved characters. ex: http://domain.com/app#first%23second
  2. Use multiple hashes and deal it in app! the first is easy but may not be implementable in your specific app.

see this doc to ensure about valid characters after #.

Comments

1

A simple way would be to use a link like this:

index.html#video_2

Then parse the hash to get the ID of the video:

if (location.hash.indexOf("#video_" === 0)) {
    var index = location.hash.indexOf('_')
    var id = location.hash.substring(index + 1)
    // use jQuery to click the 'videos' tab
    // load the video with id
}

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):

window.addEventListener("hashchange",function(event){
    // check hash for video with ID
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.