Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2013
    Thanked 0 Times in 0 Posts

    Activate Script only After Youtube API has Loaded

    I have an issue in getting the youtube API to load in time so that it works with slider script. Better if all scripts were loaded at same time so everything is ready.

    Found some info on google tho not sure how to appy this to my script:


    The javascript has been applied here:



    var tag = document.createElement('script');

    tag.src = "https://www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

    var player = new Array();
    player[0] = '';
    player[1] = '';
    player[2] = '';
    player[3] = '';
    function onYouTubeIframeAPIReady() {

    player[1] = new YT.Player('player1', {
    height: '399',
    width: '720',
    videoId: '-8eTT45778c'

    player[2] = new YT.Player('player2', {
    height: '399',
    width: '720',
    videoId: 'ukNOaKeUEQY'

    interval : 5000,
    width : 725,
    transition : 500


    Basically everything works except if you play youtube video as page is loading the slider still scrolls thro whereas it should stop so you can watch video.

    It only happens on the first slide..So there is an issue of downloading the Youtube API script. IF you click on play button later as script is fully downloaded it works fine.

    It works sometimes but not others.

    Slider script is here: wp-http://www.ravenswood.nsw.edu.au/ravenswood-demo/wp-content/themes/ravenswood/js/contentslider.jquery.js

    and also called within head of page.

    Help greatly appreciated.

  2. #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Sydney, Australia
    Thanked 932 Times in 919 Posts
    Why are you calling JavaScript from the head of the page - try moving it just before the </body> tag where 99.99% of JavaScript belongs.
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts