How can I stop a video with JavaScript in Youtube?

JavascriptWeb DevelopmentFront End Technology

To stop a video you need a valid reference to the embedded player. With Firebug, inspect your page and HTML DOM element id of “playerid” should identify the player.

Here’s an example:

<embed id="player_id" width="100%" height="100%" allowfullscreen="true"
   allowscriptaccess="always" quality="high" bgcolor="#FFFFFFF" name="playerid"
   src="http://www.youtube.com/apiplayerbeta?enablejsapi=1&playerapiid=normalplayer"
   type="application/x-shockwave-flash">

To stop the video with JavaScript, you need the reference to the player (player_id) and try the following code snippet:

var player = document.getElementById('player_id');
player.stopVideo();
raja
Published on 07-Feb-2018 08:52:58
Advertisements