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

  • Home
  • SEARCH
  • 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 3790898
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:23:10+00:00 2026-05-19T12:23:10+00:00

I embed the YouTube player on my site. Is there a way using JS

  • 0

I embed the YouTube player on my site. Is there a way using JS or the YouTube API to know when a user has clicked on the video itself, which takes him to YouTube? I can’t find a good way to differentiate Flash clicks that play/stop the video vs. clicks that cause the user to go to YouTube.

  • 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-19T12:23:10+00:00Added an answer on May 19, 2026 at 12:23 pm

    If you suscribe to the onStateChange event then you can be notified when the player state changes.

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

    Then in the onplayerStateChange You can check for a “5” value which is issued when the video is ready to be “played” for the first time or when the user clicks the video to open a new Youtube window. You should save the old value of the player state to distinguish the two cases.

    function onplayerStateChange(newState) {
        if (newState == 5) {
            if (oldState == -1) {
                // First time the video loads
            } else {
                // User has just opened a new youtube window
            }
        }
        oldState = newState;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've embedded a YouTube video onto a site (built in drupal) using the embed
I was wondering if there's a way to embed a Vimeo video in an
I'm using YouTube's iFrame API to embed videos in a page. Everything works great
Has anyone figured out a good way to embed video and audio into showoff
If I were to embed a YouTube video for example <iframe width=560 src=http://www.youtube.com/embed/25LBTSUEU0A class=player
The Youtube Player API has a bunch of functionality that I'm interested in, such
I have a YouTube video embedded on my site using an iFrame . I
What is the best way to embed an entire youtube channel into a site?
i'm trying to embed youtube video into my iphone application. I'm using UIWebView and
Regarding the Youtube API Blog they are experimenting with their new HTML5 Video Player.

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.