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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:31:55+00:00 2026-05-26T23:31:55+00:00

I have set up some test code that loads in a youtube video and

  • 0

I have set up some test code that loads in a youtube video and then a jquery click event on a link that I plan to stop the video, at the moment however when I click the link I get the error: Uncaught TypeError: Object [object Object] has no method ‘stopVideo’

Can anyone suggest where I might be going wrong with this?

 <div id="container">
    <a href="#">This is the link</a>

    <br /><br />
    <br /><br />

    <div id="player"></div>
</div>


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

        // 3. This function creates an <iframe> (and YouTube player)
        //    after the API code downloads.
        var player;
        function onYouTubePlayerAPIReady() {
            player = new YT.Player('player', {
            height: '390',
            width: '640',
            videoId: 'u1zgFlCw8Aw'
            });
        }

        function onPlayerReady(event) {
            event.target.playVideo();
        }

        $(document).ready(function() {
            $('a').click(function(e) {
                player.stopVideo();
                e.preventDefault();
            });
        });
 </script>
  • 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-05-26T23:31:55+00:00Added an answer on May 26, 2026 at 11:31 pm

    Your code snippet works as intended in a fiddle. Also, the YouTube Frame API won’t function at a file:/// protocol, because of limitations at the postMessage implementation.

    I have previously created a custom implementation of the YouTube API, available at YouTube iframe API: how do I control a iframe player that's already in the HTML?. I have successfully executed the stopVideo method at a file:/// protocol.

    If you’re running your code online, I can only think of one other cause: You’re trying to click at the link before the player is ready. To fix it, merge your functions:

        function onPlayerReady(event) {
            event.target.playVideo();
            $('a').click(function(e) { //<--- Binds event to ALL anchors! Are you sure?
                player.stopVideo();
                e.preventDefault();
            });
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Google Test Framework to set some unit tests. I have got three
I have java script code to set some of the properties of ajax controls.
I have a set of methods that do some utility work over SQL connection,
I have some code in +initialize method of a class that I'd like to
I have inherited some code that is not working as I think it should:
I have some values that I want to be able to set, and the
I have to set some routing rules in my php application, and they should
I have a set of some classes which are all capable of being constructored
Do you have some predefined set of targets which all build.xml files you create
I have been asked to set up some authentication for some content on our

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.