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 7713917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:59:31+00:00 2026-06-01T01:59:31+00:00

I have a page with multiple YouTube embedded players that I need to listen

  • 0

I have a page with multiple YouTube embedded players that I need to listen for events on. I am trying to use the solution posted as the answer to Using Youtube's javascript API with jQuery, but I am getting a strange error: (in Chrome 18.0.1025.137 beta-m)

Uncaught SyntaxError: Unexpected token %

That is the extent of the error, including stacktrace. My code is like this:

var onYouTubePlayerReady = function (id) {
var evt = '(function(){})';

alert(eval(evt)); //just to verify that the snippet is syntactically correct

var ytplayer = document.getElementById(id);
ytplayer.addEventListener("onStateChange", evt);
};

(see the other question for more context)

The error is thrown when the onStateChange event is fired. If I make evt "" or a function name, then it doesn’t throw the error (but I also get no state information).

Clearly, the error message is bogus, but anyone know if what I’m trying to do is possible?

  • 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-01T01:59:32+00:00Added an answer on June 1, 2026 at 1:59 am

    Actually, turns out it’s incredibly stupid. Running the code in Firefox yielded a real error message:

    syntax error
    
    
    try { __flash__toXML(%28function%28%29%7B%7D%29(5)) ; } catch (e) { "<undefined/...
    ---------------------^
    

    So, apparently, it needs to be serializable to XML in order to be used as a callback. Which is really kind of annoying.

    My solution was something like this:

    var ytCallbackID = 1;
    
    var makeYTCallback = function (func) {
        var ret = "ytCallback" + (ytCallbackID++);
        window[ret] = func;
    
        return ret;
    }
    
    var onYouTubePlayerReady = function (id) {
        var evt = makeYTCallback(function(state) {
            onYouTubePlayerStateChange(id, state);
        });
    
        var ytplayer = document.getElementById(id);
        ytplayer.addEventListener("onStateChange", evt);
    };
    

    I haven’t fully tested it (since I did this right at the end of the day yesterday), but I think it’ll work.

    Got around to testing it, and it works like a charm! It’s a bit fugly, both in idea and implementation, but it works and that’s what’s important 🙂

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

Sidebar

Related Questions

I have a page with multiple popovers that I am trying to dismiss when
I have a page which displays multiple (usually 10) embedded videos. The videos use
I have a page with multiple forms that I submit via Ajax POSTs serially.
I have a page that uses multiple dialogs for different things. Some dialogs may
I have a page that has multiple forms. Anytime the user clicks an input
I have a page with multiple links that each perform different AJAX calls and
I have a page with multiple Matplotlib figures embedded. The figures get inserted/manipulated via
I have a page that uses multiple UpdatePanels and a MasterPage. Upon switching my
I have a page that contains multiple checkbox input elements. Toggling these alter the
I have a form page that posts to another page where multiple fields as

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.