Search code examples
javascriptreferenceerror

"Uncaught ReferenceError: wistiaEmbed is not defined"


I get this error on this page: http://pages.purevisionmethod.com/myopia-class-replay/

I try to get this code execute:

<div style="width:1240px;max-width:100%;text-align:center;margin:5rem auto 0 auto;">
<script src="//fast.wistia.com/assets/external/E-v1.js" async></script><div class="wistia_responsive_padding" style="padding:56.25% 0 0 0;position:relative;"><div class="wistia_responsive_wrapper" style="height:100%;left:0;position:absolute;top:0;width:100%;"><div class="wistia_embed wistia_async_4uf1zbu4se videoFoam=true" style="height:100%;width:100%"> </div></div></div></div> 
<script>
window._wq = window._wq || [];

wistiaEmbed.bind("secondchange", function (s) {
  if(s === 20) {
    $('.hiding').fadeIn(500);
  }
});
</script>

I get the error: “Uncaught ReferenceError: wistiaEmbed is not defined”

I cannot work out what's going on. The reference should be defined by <script src="//fast.wistia.com/assets/external/E-v1.js" async></script>

But no matter where I move the file, if in the header, footer, anywhere, I still get the same error.

Can you see why?

Thanks!!


Solution

  • Sorry, I used the wrong type of code to integrate this.

    So, for anyone using Wistia who bumps into the same problem:

    You need to use the API code to get this to work:

    <div class="wistia_responsive_padding" style="padding:56.25% 0 0 0;position:relative;"><div class="wistia_responsive_wrapper" style="height:100%;left:0;position:absolute;top:0;width:100%;">
    <div id="wistia_INSERT_YOUR_VIDEO_ID_HERE" class="wistia_embed" style="height:100%;width:100%">&nbsp;</div></div></div>
    <script src="//fast.wistia.com/assets/external/E-v1.js" charset="ISO-8859-1"></script>
    <script>
    wistiaEmbed = Wistia.embed("INSERT_YOUR_VIDEO_ID_HERE");
    </script>
    <script>
    (function($){
    wistiaEmbed.bind("secondchange", function (s) {
      if(s === 20) {
         $('.hiding').show();
    
      }
    });
    })(jQuery);
    </script>
    

    So, you have to paste in you video ID where I placed: INSERT_YOUR_VIDEO_ID_HERE.

    You can find that in the normal Wistia javascript embed code. It's the only weird number code in it.

    For <div id="wistia_INSERT_YOUR_VIDEO_ID_HERE" you must have the wistia_ in front of the video ID, so it works.

    Hope that helps anyone!