I am using video.js and I'd like to use a class (i.e. class="next-project" href="") to redirect to a URL at the end of video instead of the actual URL as this solution indicates - any ideas?
Asked
Active
Viewed 481 times
1
-
I'm confused - do you want the url in the class attribute? – Erik Inkapööl Aug 11 '15 at 17:37
-
hi Erik - sorry if i wasn't clear. No I'm setting up a [page] (http://andylilien.com/reel/movies/Bartenura_BlueSkies/index_alex.html) with a previous and next prompt - and I'd like to redirect to a page when the movies ended with the class in that prompt (next-project) so that I'm not specifying the URL in every script. like this: Basically I want the script to go to whatever link has that class in it. is that clearer? – REELHERO Aug 11 '15 at 17:58
1 Answers
0
Using jQuery instead, since you have that on your site. Assuming you want to redirect the user using the href
attribute of the first anchor element on video ended I recommend the following approach:
$(function() {
var video = $("video");
video.on("ended", function() {
var href = $(".next-project").attr("href");
window.location = href;
});
});

Erik Inkapööl
- 378
- 2
- 11
-
that looks exactly what Im looking for but I'm not sure what you mean by video variable. The video id has a video-js class i.e. – REELHERO Aug 11 '15 at 19:02
-
@REELHERO see my edit. If my answer answered your question don't forget to upvote and accept it :) – Erik Inkapööl Aug 11 '15 at 19:15
-
thank you Erik - one more question - and this may be my inexperience with video API - the var video = videojs("movie"); that references the movie where does that tag go? (sorry i dont have enough of a reputation to upvote - i tried :( – REELHERO Aug 11 '15 at 19:39
-
I'm a little unclear on what you are referring to. The line declaring the `var video` is supposed to go anywhere above the line starting with `video.on(`. If you were referring to where I got the string `"movie"` from, that's the `id` of your video element. Hope this helps! – Erik Inkapööl Aug 12 '15 at 06:38
-
thats it. and it works great with one strange flaw.. http://andylilien.com/reel/movies/Bartenura_BlueSkies/index_alex2.html let the movie play (its :60) it will go to the link. But if you reload the above link it wont work at least in chrome. browser issue? and thank you for the upvote karl it changed my status around here :) – REELHERO Aug 12 '15 at 16:24
-
this was the script i used: `var video = document.querySelectorAll(".video-js")[0]; video.addEventListener("ended", function() { var nextProjectElements = document.querySelectorAll(".next-project"); var firstElement = nextProjectElements[0]; var href = firstElement.href; window.location = href; });` – REELHERO Aug 12 '15 at 16:30
-
it seems to be a browser issue because it works pretty perfectly in safari – REELHERO Aug 12 '15 at 16:49
-
Check if the above code works. Video-js will make divs and other things around the video element, so selecting by element should work. I tried it out on your site on reload and it seems to do the job. Let me know if it still doesn't work – Erik Inkapööl Aug 12 '15 at 18:38
-
Erik you are my hero :) it works perfectly thank you. I wish I could upvote you. – REELHERO Aug 12 '15 at 20:34
-