Title: JS Function on Start
Last modified: August 31, 2016

---

# JS Function on Start

 *  Resolved [PumpaXXL](https://wordpress.org/support/users/pumpaxxl/)
 * (@pumpaxxl)
 * [10 years ago](https://wordpress.org/support/topic/js-function-on-start/)
 * Hey Kyle, fantastic job with this plugin!
 * Just a quick question. I need to run my javascript function upon the start of
   the video. Can you please recommend the best way how to do it?
 * Thanks!
    Pavel.
 * [https://wordpress.org/plugins/video-embed-thumbnail-generator/](https://wordpress.org/plugins/video-embed-thumbnail-generator/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [Kyle Gilman](https://wordpress.org/support/users/kylegilman/)
 * (@kylegilman)
 * [10 years ago](https://wordpress.org/support/topic/js-function-on-start/#post-7454524)
 * Assuming you’re using the Video.js player, this should run when a video starts
   playing
 *     ```
       jQuery(document).ready( function() {
            if  ( typeof videojs != "undefined" ) {
                 jQuery.each( videojs.getPlayers(), function() {
                      this.on('play', function() {
                            //add your JS function here
                      });
                 });
            }
       });
       ```
   
 *  Plugin Author [Kyle Gilman](https://wordpress.org/support/users/kylegilman/)
 * (@kylegilman)
 * [10 years ago](https://wordpress.org/support/topic/js-function-on-start/#post-7454625)
 * I just realized that code also assumes that jQuery is loaded on the page, which
   isn’t necessarily true if you don’t have a video on the page. You might want 
   to check for jQuery too.
 *     ```
       if  ( typeof jQuery != "undefined" ) {
            jQuery(document).ready( function() {
                 if  ( typeof videojs != "undefined" ) {
                      jQuery.each( videojs.getPlayers(), function() {
                           this.on('play', function() {
                                 //add your JS function here
                           });
                      });
                 }
            });
       }
       ```
   
 *  Thread Starter [PumpaXXL](https://wordpress.org/support/users/pumpaxxl/)
 * (@pumpaxxl)
 * [9 years, 12 months ago](https://wordpress.org/support/topic/js-function-on-start/#post-7454687)
 * Hi Kyle, the Chrome console is giving me the following error:
 * “(index):423 Uncaught TypeError: videojs.getPlayers is not a function”
 * I tried to put it in the head and then after the video. Both gave me the same
   results. Any sugestions?
 * Thanks, Pavel.
 *  Plugin Author [Kyle Gilman](https://wordpress.org/support/users/kylegilman/)
 * (@kylegilman)
 * [9 years, 12 months ago](https://wordpress.org/support/topic/js-function-on-start/#post-7454688)
 * That works for me in the header and the footer of the page. Are you using Video.
   js as your player? Are you running the latest version of the plugin? Have you
   modified the script I posted at all? Did you enclose it in `<script>` tags?
 *  Thread Starter [PumpaXXL](https://wordpress.org/support/users/pumpaxxl/)
 * (@pumpaxxl)
 * [9 years, 12 months ago](https://wordpress.org/support/topic/js-function-on-start/#post-7454690)
 * Hi, yes, I am using the Video.js option and I have plugin version 4.6.7. You 
   can see it here [http://www.rakovinaprostaty.org/lekce-vzor/](http://www.rakovinaprostaty.org/lekce-vzor/).
 * Thanks!
 *  Thread Starter [PumpaXXL](https://wordpress.org/support/users/pumpaxxl/)
 * (@pumpaxxl)
 * [9 years, 12 months ago](https://wordpress.org/support/topic/js-function-on-start/#post-7454694)
 * Kyle, I have tested it also here: [http://jakna.org/](http://jakna.org/). It 
   is simple testing page, no tons of other code like the previous example. You 
   can still see the error.
 * Thanks, Pavel.
 *  Plugin Author [Kyle Gilman](https://wordpress.org/support/users/kylegilman/)
 * (@kylegilman)
 * [9 years, 12 months ago](https://wordpress.org/support/topic/js-function-on-start/#post-7454695)
 * I wasn’t able to look at the video at [http://www.rakovinaprostaty.org/lekce-vzor/](http://www.rakovinaprostaty.org/lekce-vzor/)
   because I never got a registration confirmation email, but the video at [http://jakna.org/](http://jakna.org/)
   doesn’t have that error in Chrome, Safari, or Firefox.
 *  Thread Starter [PumpaXXL](https://wordpress.org/support/users/pumpaxxl/)
 * (@pumpaxxl)
 * [9 years, 12 months ago](https://wordpress.org/support/topic/js-function-on-start/#post-7454696)
 * Kyle, I have cleared the Chrome cache and it works fine. So sorry about that.
   Sent you some donation money.
 * Have a nice day!
    Pavel.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘JS Function on Start’ is closed to new replies.

 * ![](https://ps.w.org/video-embed-thumbnail-generator/assets/icon.svg?rev=2965979)
 * [Videopack](https://wordpress.org/plugins/video-embed-thumbnail-generator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/video-embed-thumbnail-generator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/video-embed-thumbnail-generator/)
 * [Active Topics](https://wordpress.org/support/plugin/video-embed-thumbnail-generator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/video-embed-thumbnail-generator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/video-embed-thumbnail-generator/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [PumpaXXL](https://wordpress.org/support/users/pumpaxxl/)
 * Last activity: [9 years, 12 months ago](https://wordpress.org/support/topic/js-function-on-start/#post-7454696)
 * Status: resolved