Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8765275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:14:27+00:00 2026-06-13T16:14:27+00:00

We have a Facebook Tab application (probably not relevant) that contains a YouTube video.

  • 0

We have a Facebook Tab application (probably not relevant) that contains a YouTube video.

Everything works fine on the first occasion the page is loaded from an empty cache. On subsequent page loads, however, once the video stops loading, the onStateChange handler simply isn’t firing in Internet Explorer.

Everything works fine in Chrome and Firefox, this problem only seems to affect IE and, weirdly, only occurs from a non-empty cache. It looks very similar to gdata-issues #2942, except that issue has Status: Fixed.

The relevant chunks of our code are as follows:

Page

<!DOCTYPE html>

...

<div class="player-surround">
   <div id="ytplayer">
       You need Flash player 9+ and JavaScript enabled to view this video.
   </div>
</div>

...

<script src="//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script type="text/javascript">
var params = { allowScriptAccess: "always" };
var atts = { id: "ytplayer" };
// YouTube video ID redacted here
swfobject.embedSWF("http://www.youtube.com/v/XXXXXXXXXXXXXX?enablejsapi=1&playerapiid=ytplayer&version=3",
   "ytplayer", "587", "330", "8", null, null, params, atts);
</script>
<script src="//www.youtube.com/player_api"></script>

Included JavaScript

MFA.onPlayerStateChange = function(evt) {
    var state = this.getPlayerState();
    log('158: STATE CHANGED: ' + state);

    // Then do some stuff, but the `log` call above doesn't fire
}

MFA.getPlayerState = function() {
    var playerState;

    if (this.ytplayer) {
        playerState = this.ytplayer.getPlayerState();
        
        switch (playerState) {
            case 5:  return 'video cued';
            case 3:  return 'buffering';
            case 2:  return 'paused';
            case 1:  return 'playing';
            case 0:  return 'ended';
            case -1: return 'unstarted';
            default: return 'Status uncertain';
        }
    }
};

(Obviously, I’ve missed a bunch of unrelated code out from this issue.)

Does anyone have any ideas why everything would work fine, unless IE has seen the page before? I could understand if it never worked in IE, but it works ok when the cache is empty, but fails when you reload the page.

All ideas gratefully received.


Edit

Greg Schechter pointed out that my code sample uses the swfobject.embedSWF code, rather than the iframe embed code.

We did originally use the iframe embed code:

var s = {
   playerHeight: '330',
   playerWidth: '587',
   playerVars: { 'rel': 0 },
   videos: {
      stage1: 'XXXXXXXXXXXXXX', // ...
   }
};

window.onYouTubePlayerAPIReady = function() {
   MFA.ytplayer = new YT.Player('ytplayer', {
      height: s.playerHeight,
      width: s.playerWidth,
      videoId: s.videos.stage1,
      playerVars: s.playerVars,
      events: {
         'onReady': $.proxy(MFA.onPlayerReady, MFA),
         'onStateChange': $.proxy(MFA.onPlayerStateChange, MFA),
         'onError': $.proxy(MFA.onPlayerError, MFA)
      }
   });
} 

, but this was exhibiting the same problem. The swfobject.embedSWF code was added in subsequently as an attempt to fix the problem, as we have previously seen problems with IE being over-paranoid with API access across domains from iframes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:14:28+00:00Added an answer on June 13, 2026 at 4:14 pm

    So I had to put this down and get back to another project, but one of my colleagues has managed to find a solution. The rest of this answer is taken directly from his email to me.

    So here’s the long version of how we fixed this (very annoying!) IE issue… It turns out it was a case of changing the way the YouTube Player API gets called in the default.aspx page.

    We replaced this:

    <script src="//www.youtube.com/player_api"></script>
    

    With the following JavaScript in a <script> tag:

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

    (that’s how it’s specified in the API reference).

    Also I noticed that Google specify iframe_api but we were using player_api. That may have compounded the problem, but just changing that didn’t fix it.

    The way [our tech director] explained it to me, was that the original way was fine the first time the page loads, as everything is loaded fresh, and the YouTube API has enough time to load before init.js initialises.

    But then when you reload the page, init.js was cached and probably loading too quickly, before the API was ready, hence failing when it tried to fire onYouTubePlayerReady. Doing it the above way still starts off init.js, but also starts loading the iframe_api at the same time (by effectively inserting it as the first script tag in the list). It may also be slightly connected to a known issue with IE9 where AJAX calls can create a memory leak, but not sure.

    I am seeing the same error (very) intermittently on other browsers, which I imagine is down to fluctuating RTDs between here and whatever data centre the Google API is connecting to. If it’s out of sync by enough for init.js to get there before the API is ready, onYouTubePlayerReady will fail. But then a simple refresh will fix it.

    What was interesting is that just putting the YouTube API as the first script tag doesn’t make a difference!

    So I guess the lesson is, that when we are dealing with third party APIs, iframes, and Internet Explorer, we need to make sure we use asynchronous loading for all the third party APIs, especially if YouTube and Facebook are both involved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a client that wants their tab application to be searchable in Facebook.
I have a Facebook application that has a user profile tab. The specs of
We currently have an iframe-based Facebook canvas application in the works. The canvas portion
I have a web application that I am trying to port to Facebook. The
I have this facebook application which adds a custom tab to fan pages. You
When building a Facebook tab application the first page receives the signed request, my
I have a Facebook Application that installs on users' Page tabs. I would like
I have created this fan page http://www.facebook.com/pages/ohlala/327385737341 and added an application on tab "Special
I have created a business page on facebook and added application to a tab.
I currently have an Application on the Facebook Tab, and am wondering if there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.