Support » Plugin: JW Player for Flash & HTML5 Video » Targeting videos with javascript

  • Hi there,

    I’m trying to figure out how to target the video to check when it has finished playing. I need to do something along the lines of

    onComplete: function() {
    alert( ‘video complete’)

    Not exactly that, but you get the idea. I know I can use shortcode like so:
    [jwplayer mediaid=”221″ onComplete=”function() {alert(‘video complete’);}”]
    but the problem with that approach is that the client has to add that into the shortcode every time they upload a video to a post, which is impractical. I need to be able to target the video with javascript from the template file.

    Did a lot of Googling but was unable to find an actual answer to this.


Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author JW Player


    The best way to do this with the plugin is to do this in the shortcode. Otherwise, you are going to have to hack this into your site’s template.

    Like I said, having to type that into the shortcode every time is impractical. Looks like I’ll have to hack the plugin :-/

    I would definitely recommend adding the ability to add callbacks without typing it into the shortcode as a feature.

    Plugin Author JW Player


    How would it be easier for the client to update the events in a hacked version of the plugin than via the recommended, and documented, method?

    It would be easier if I could just target the video via javascript from a template file. Obviously much easier than if a non-javascript has to remember to paste a bunch of javascript into a shortcode, instead of just uploading the video and clicking “insert into post”.

    I definitely don’t want to hack the plugin, but it doesn’t make sense to force the client to have to do that extra work when normally I would just write some javascript that they would never have to touch (like with the non-wordpress version of JW player)

    Plugin Author JW Player


    You could always write that into the shortcode as well though, it works.

    If you mean the code in the plugin that generates the shortcode, then yeah that’s what I’ll probably have to do. If you’re just talking about using the shortcode in a post, that’s what I’m trying to avoid, as it won’t be me adding the videos, it will be non-js savvy editors. I’m not sure I’m explaining my issue well enough, but that’s ok, I’m on the right track looking through the plugin code now.

    Plugin Author JW Player



    For others who have this problem, you don’t need to have the callbacks in the shortcode, nor do you have to hack the plugin as suggested. The js just needs to come AFTER the javascript generated by the plugin, which is why it wasn’t working for me. In my case, just adding

    jwplayer(‘jwplayer-1’).onComplete(function() {

    worked for me (to close a colorbox once the video completed).

    Plugin Author JW Player


    Thanks for sharing!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Targeting videos with javascript’ is closed to new replies.