javascript - Uncaught ReferenceError: videojs is not defined. videojs async loading -


  1. so have js file follows:-

(function(){      console.log("starting point");        // creating , appending scripts dynamically        function createscript(src) {        console.log("script js");	        var script = document.createelement('script');        script.src = src;        document.getelementsbytagname('head')[0].appendchild(script);      }            // end script tags here        function createlink(href) {        console.log("script links");	        var link = document.createelement('link');          link.href = href;        link.rel = "stylesheet";        link.type = "type/css";        document.getelementsbytagname('head')[0].appendchild(link);      }             // div 1      // create main div hold        createscript('http://vjs.zencdn.net/4.7.1/video.js');      createscript('lib/videojs-contrib-ads/videojs.ads.js');      createscript('lib/vast-client.js');      createscript('videojs.vast.js');        createlink('http://vjs.zencdn.net/4.7.1/video-js.css');      createlink('lib/videojs-contrib-ads/videojs.ads.css');      createlink('videojs.vast.css');            console.log("create maindiv");      var maindiv = document.createelement('div');      maindiv.id  = 'ad_placement';      // maindiv.style.float = "right";      var currentscript = document.currentscript;      currentscript.parentelement.insertbefore(maindiv, currentscript);      // document.body.appendchild(maindiv);      console.log("end maindiv");         // end main div here          // div 2       // div hold video            console.log("create innerdiv")      var divcontainer = document.createelement('div');      divcontainer.class = 'example-video-container';      divcontainer.style.display = 'inline-block';      maindiv.appendchild(divcontainer);         console.log("create innerdiv")        // end parent div here (parent of video div/tag)        // video player below       // create video tag html video player      console.log("video creation started");        var video = document.createelement('video');      video.id = 'vid2';      video.width = 300;      video.height = 250;      video.class = 'video-js vjs-default-skin';            video.autoplay = true;      video.controls = true;      video.muted = true;      video.preload = 'auto';      video.poster = "http://www.jqueryscript.net/images/simplest-responsive-jquery-image-lightbox-plugin-simple-lightbox.jpg";      //video.data-setup = '{}';             // function create sources video      function addsourcetovideo(element, src, type) {        var source = document.createelement('source');          source.src = src;        source.type = type;          element.appendchild(source);      }        addsourcetovideo(video, 'http://grochtdreis.de/fuer-jsfiddle/video/sintel_trailer-480.mp4', 'video/mp4');      addsourcetovideo(video, 'http://video-js.zencoder.com/oceans-clip.mp4', 'video/webm');      addsourcetovideo(video, 'http://video-js.zencoder.com/oceans-clip.mp4', 'video/ogg');        console.log("video creation end");          console.log("para started");        var paragraph = document.createelement('p');      paragraph.innerhtml = "video playback not supported";      video.appendchild(paragraph);        video.load();      //video.play();      divcontainer.appendchild(video);        console.log("para end");      // video player creation ends here            console.log("before calling videojs");      var vid2 = videojs('vid2');      console.log("after calling videojs");      vid2.muted(true);            vid2.ads({        timeout: 5000      });            vid2.vast({        url: 'vast_tag_url'      });        vid2.on('readyforpreroll', function() {        vid2.ads.startlinearadmode();         vid2.one('ended', function() {          vid2.ads.endlinearadmode();          console.log("ad finished");          document.getelementbyid('adplacement').innerhtml="<img src='https://wallazee.global.ssl.fastly.net/images/variant/20140109-11d5e6789afea899c324f5d4cbfa00eca24c58c8b790e1d6305c36e-1024.png' width=300 height=250 border=0/>";        });        });        vid2.on('adtimeout', function() {          console.log("timout happened")          document.getelementbyid('adplacement').innerhtml="<img src='https://wallazee.global.ssl.fastly.net/images/variant/20140109-11d5e6789afea899c324f5d4cbfa00eca24c58c8b790e1d6305c36e-1024.png' width=300 height=250 border=0/>";      });        console.log("end of file");    })();

  1. so getting video.js not defined error when include file in html page. need javascript solution. (i can't use jquery)
  2. where wrong.it works on normal html page when have css , js in head div video , js functions in body.
    1. when created js , imported problem


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -