![](https://secure.gravatar.com/avatar/25989c27e4113e0921fbf29416ffb9fc?rating=PG&size=50&default=https%3A%2F%2Fcdn.desk.com%2Fassets%2Funknown_user_50-8ad5644bbe6b1bd7454f2ea465f782bd.png)
Calling JS API functions when jwplayer is defined
Hello,
I have a custom script that loads JWPlayer JS API functions to enhance our users video experience.
The issue I am having is that this script loads on every page of our website (in wordpress) and on those pages where JWPlayer is not embedded it keeps throwing errors:
Uncaught TypeError: jwplayer(...).on is not a function
The script I am talking about is here: https://www.visualsp.com/wp-content/themes/VisualSP/js/player.js
IS there a way to defer executing of the code in this script until we know JW Player is required and loaded on the page?