Stop embedded youtube iframe?
Unfortunately these API's evolve very fast. As of May 2015, the proposed solutions don't work anymore, as the player object has no stopVideo
method.
A reliable solution is to be found in this page (1) and it works with an:
<iframe id="youtube_player" class="yt_player_iframe" width="640" height="360" src="http://www.youtube.com/embed/aHUBlv5_K8Y?enablejsapi=1&version=3&playerapiid=ytplayer" allowfullscreen="true" allowscriptaccess="always" frameborder="0"></iframe>
and the following JS/jQuery code:
$('.yt_player_iframe').each(function(){
this.contentWindow.postMessage('{"event":"command","func":"stopVideo","args":""}', '*')
});
Youtube Iframe disable pause video
There's no way to disable pausing entirely.
You could listen for YT.PlayerState.PAUSED
events in an onStateChange handler and immediately call playVideo() when you detect one, but... I don't know, that sounds like it wouldn't be very user-friendly.
Disable play/pause button of a YouTube video
I disabled it here:
https://codepen.io/polinq/pen/mdyWmMm
iframe{
pointer-events: none; /* Disable any user interaction at all */
}
Is that what you are looking for?
How can I play/pause youtube player on its native site itself using javascript?
This is very simple on youtube video page.
Try this simple js code:
var video = document.querySelector("video");
if (video.paused){video.play();} else {video.pause();}
But for embedded Youtube videos you may want to review through the Youtube JavaScript API Reference docs. Read this for more details: https://stackoverflow.com/a/15165166/1225070
For html5 Videos.
Try this:
var vid = document.getElementById("myVideo");
function playVid() {
vid.play();
}
function pauseVid() {
vid.pause();
}
Related Topics
Javascript: Undefined !== Undefined
Create an Object from an Array of Keys and an Array of Values
How to Use Ranges in a Switch Case Statement Using JavaScript
How to Get Selector from Jquery Object
Invert Y Axis of L:Crs.Simple Map on Vue2-Leaflet
How to Split Comma Separated String Using JavaScript
How Does a Function in a Loop (Which Returns Another Function) Work
Why Does JavaScript's Eval Need Parentheses to Eval JSON Data
How to Add/Remove a Class in JavaScript
Difference Between Date(Datestring) and New Date(Datestring)
The Definitive Best Way to Preload Images Using JavaScript/Jquery
Can a Site Invoke a Browser Extension
Setting a Variable to Get Return from Call Back Function Using Promise
No-JavaScript Detection Script + Redirect