Open vdotm opened 5 years ago
Changing this :
To this worked for me:
'<iframe class="mfp-iframe" src="//about:blank" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'+
This should also be OK:
'<iframe class="mfp-iframe" src="//about:blank" frameborder="0" allow="autoplay" allowfullscreen></iframe>'+
(YouTube embed code comes with the first version.)
Also had to change this:
to this:
src: 'https://www.youtube.com/embed/%id%?autoplay=1'
I didn't edit that file, but /dist/jquery.magnific-popup.js
.
Here:
and here:
But this file is probably generated from /src/js/iframe.js
.
You shouldn't need to edit any core files. I found that in addition to including options to reformat the URL, you also need to include the option to modify the iframe markup. Make sure to include allow="autoplay"
on the opening iframe tag.
{
type: 'iframe',
iframe: {
markup: '<div class="mfp-iframe-scaler">' +
'<div class="mfp-close"></div>' +
'<iframe class="mfp-iframe" frameborder="0" allow="autoplay"></iframe>' +
'</div>',
patterns: {
youtube: {
index: 'youtube.com/',
id: 'v=',
src: 'https://www.youtube.com/embed/%id%?autoplay=1'
}
}
}
}
Isn't this something that should be done by magnific popup automatically?
The solution from @apmeyer works perfectly. Even so I would like to know why the "Open YouTube video" example on Magnific-Popup homepage works without the iframe markup and patterns.
Not sure exactly when this changed, but in Chrome v96 the @apmeyer solution above, as well as the video examples on the Magnific Popup homepage no longer work:
just add this "mfp-iframe" css class in the trigger button. for example:
<a href="https://www.youtube.com/watch?v=pVE92TNDwUk" class="mfp-iframe transparent-link">WATCH VIDEO</a>
As you can see in the anchor I have added the class name in the class list. And "Booooom"
add params mute=1 it's work for me ?autoplay=1&mute=1
<script>
$(document).ready(function() {
$('.popup-youtube').magnificPopup({
type: 'iframe',
iframe: {
markup: '<div class="mfp-iframe-scaler">'+
'<div class="mfp-close"></div>'+
'<iframe class="mfp-iframe" frameborder="0" allowfullscreen allow="autoplay *; fullscreen *"></iframe>'+
'</div>',
patterns: {
youtube: {
index: 'youtube.com/',
id: function(url) {
var m = url.match(/[\\?\\&]v=([^\\?\\&]+)/);
if ( !m || !m[1] ) return null;
return m[1];
},
src: '//www.youtube.com/embed/%id%?autoplay=1&iframe=true'
},
vimeo: {
index: 'vimeo.com/',
id: function(url) {
var m = url.match(/(https?:\/\/)?(www.)?(player.)?vimeo.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/);
if ( !m || !m[5] ) return null;
return m[5];
},
src: '//player.vimeo.com/video/%id%?autoplay=1'
}
}
}
});
});
</script>
HTML:
<a class="popup-youtube mfp-iframe" href="http://www.youtube.com/watch?v=0O2aH4XLbto">Open YouTube video</a>
On clicking the link the popup shows up with video - but does not autoplay it. Plays only on clicking again the popped up youtube button. I tried with different options for autoplay. Any help would be much appreciated!
This is the link
<a href="https://www.youtube.com/watch?v=8Shndkrgc88" class="video" >
With this script