Jason
Jason

Reputation: 2298

How to create a clickable timestamp link on an embedded youtube video with javascript?

I would really like to have clickable time links on my website that will jump to specific times within my embedded youtube video. I know that this is possible within youtube itself (built in function on youtube where you just put the time you want in the format (0:00) and users can click it to jump to that point).

I was wondering if it is possible to mimic this function somehow with embedded youtube videos and javascript?

Upvotes: 0

Views: 5204

Answers (1)

cch
cch

Reputation: 3386

You can use the Youtube iFrame API. There is a function to get the current timestamp:

player.getCurrentTime():Number 

Returns the elapsed time in seconds since the video started playing.

player.getDuration():Number

Returns the duration in seconds of the currently playing video. Note that getDuration() will return 0 until the video's metadata is loaded, which normally happens just after the video starts playing.

Use them like so:

ytplayer = document.getElementById("youtube_player");
ytplayer.getCurrentTime();

Upvotes: 3

Related Questions