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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:08:19+00:00 2026-06-03T23:08:19+00:00

I am playing an embeded youtube video with the play() function. This is all

  • 0

I am playing an embeded youtube video with the play() function. This is all using the youtube api. Below is the code I have. It works perfectly in chrome and IE but in firefox it doesnt play.

    alert(typeof ytplayer);

This bit of code is showing what type “thing” ytplayer is. In chrome and IE it will come up with object (the video is embed with the object method). In firefox it says undefined so something is going wrong there.

I have a test website with it here: http://lostinawesome.blogspot.com.au/2012/04/test-post.html

click the play button or the image to play the youtube audio. In firefox it probably wont work for you.

Any ideas to get this to play in FF?

my code:

javascript:

    function onYouTubePlayerReady(playerId) {
    var player = document.getElementById("ytplayer");
    player.addEventListener("onStateChange", "onytplayerStateChange");
}

function onytplayerStateChange(newState) {
    alert("New state " + newState); 
}

   function play() {

   alert(typeof ytplayer);

   if (ytplayer) {
ytplayer.playVideo();
  }
}

html:

    <object data="http://www.youtube.com/v/u8C-ZTQJIkU?enablejsapi=1&amp;playerapiid=ytplayer&amp;version=3" height="400" id="ytplayer" type="application/x-shockwave-flash" width="550"><param name="allowScriptAccess" value="always">


    <param name="movie" value="http://www.youtube.com/v/u8C-ZTQJIkU?enablejsapi=1&amp;playerapiid=ytplayer&amp;version=3" >


    </param>
    <param name="allowScriptAccess" value="always">


    </param>
    </object>

    <a href="javascript:void(0);" onclick="play();">Play</a>

Working code:

I just had to change to have var ytplayer = document.getElementById("ytplayer");
because ytplayer wasnt declared as a variable anywhere but for some reason it worked in chrome and IE anyway.

    function play() {
    var ytplayer = document.getElementById(&quot;ytplayer&quot;);
    alert(typeof ytplayer);

      if (ytplayer) {
        ytplayer.playVideo();
      }
    }
  • 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-03T23:08:21+00:00Added an answer on June 3, 2026 at 11:08 pm

    You need to explicitly select the element rather than just using its ID since it won’t work in all browsers, as you’re seeing.

    Change to

    var ytplayer = document.getElementById('ytplayer');
    ytplayer.playVideo();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

right now i m using this code for playing youtube videos <?php // Replace
I'm using the code from this question to autoplay an iframe embedded Youtube video
I want to have an embedded chromeless youtube video preload its video WITHOUT playing
So I managed to play an embeded youtube video in my app. After I
I have a video playing on my page. I want to show and hide
I am using FLVPlayback Component in Flash AS3 to play an F4V video hosted
I have embedded flowplayer in my site but the flowplayer is not playing video
I have been playing around with the bluetooth API for Android 2.2 (API level
I've implemented the youtube api and it works as expected in a regular computer
I'm playing whack-a-mole trying to make an embedded video file work on all major

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.