How can I stop a video with Javascript in Youtube?

Your video is requesting w/ the JSAPI enabled, so you are very close! All you need is a valid reference to the embedded player. Inspecting your page revealed that you are using the HTML DOM element id of “playerid” to identify your player.

Example:

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

To obtain a reference to the player and then stop the video use the following code:

var myPlayer = document.getElementById('playerid');
myPlayer.stopVideo();

Leave a Comment