I have a YouTube video iframe embedded inside a popup modal that appears after a few seconds of being on a site. I have tried multiple things with the iframe parameters, jQuery and CSS but the video always shows the low-quality, blurry thumbnail when the modal appears. If I right click and reload the iframe, then it loads the proper high-quality preview thumbnail.
The actual video is fine and has an HD resolution of 1080 so it's not like the video is poor quality.
- I tried adding
target=_selfto the iframe tag - I tried
$( '#iframe' ).attr('src', $( '#iframe' ).attr('src')); - I tried
$( '#iframe' ).attr( 'src', function ( i, val ) { return val; }); - I tried changing the
widthandheightparameters of the iframe to be larger than 560 and 315, and even removed both entirely but it didn't change anything. - I tried having the iframe src empty by default and populated it using jQuery but that didn't work:
$( '#iframe' ).attr('src', 'https://www.youtube.com/embed/TL90qfsFplc');
<div class="subscribe-modal-mask">
<div class="subscribe-modal-container">
<div class="video-container">
<iframe id="iframe" width="900" height="315" target="_self" src="https://www.youtube.com/embed/TL90qfsFplc" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<div class="modal-head">
<p id="modal-h1">Watch Now - Change Your Image of Dumpsters</p>
<div class="subscribe-modal-close">X</div>
<p class="modal-text">Sign up to learn how making the switch can save you time, money, and more
money</p>
{!! do_shortcode('[gravityform id="4" title="false" description="false"]') !!}
</div>
</div>
</div>
<script>
(function ($) {
$(document).ready(function () {
function createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 12000));
var expires = "; expires=" + date.toGMTString();
} else var expires = "";
document.cookie = name + "=" + value + ';' + expires + "; path=/; secure: true;";
}
$( '#iframe' ).attr('src', $( '#iframe' ).attr('src'));
$('.subscribe-modal-close').on('click', function () {
createCookie('hedstromenvguest', '1', '.333333333');
$('.subscribe-modal-mask').fadeOut(1000);
});
$('.subscribe-modal-mask').mousedown(function(e) {
var clicked = $(e.target); //get the element clicked
if (clicked.is('.subscribe-modal-container') || clicked.parents().is('.subscribe-modal-container')) {
return; // click happened within the dialog, do nothing here
} else { //click was outside the dialog, so close it
$('.subscribe-modal-mask').fadeOut(1000);
}
});
$('.subscribe-modal-mask').on('click', function () {
createCookie('hedstromenvguest', '1', '.333333333');
});
$('.subscribe-modal-container .gform_button').on('click', function () {
createCookie('hedstromenvguest', '1', '.333333333');
});
});
})(jQuery);
</script>
.video-container {
position: relative;
overflow: hidden;
width: 100%;
padding-top: 36.25% !important;
iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
max-width: 100%;
height: 100%;
border: 0;
}
}
Somehow, I have to get the video in the modal to load the HQ preview first and not the low quality, blurry one. Otherwise, it looks terrible to users.