The page displayed a video in <iframe>. When cookies are allowed then <iframe> has a [src] attribute <iframe src="http://video....">, when are disabled then has a [data-cookieblock-src] attribute <iframe data-cookieblock-src="http://video....">. When cookies are disabled then the page doesn't display a video, instead display an image banner.
The page display an image in a div with a class="hero-banner" and an iframe in a div with a class="youtube-banner". I check which attribute has an iframe and depending on it I toggle a display value block or none. It works as I want but there is one issue. When I visit the page the first time and I allow the page to use cookies, a video should be displayed, and it is only if I refresh the page. I can see that hero-banner and youtube-banner got a display styles. My question is how could I fix this issue?
$("iframe").each(function() {
var regexVimeo = /(?:http:|https:|)\/\/(?:player.|www.)?vimeo\.com\/(?:video\/|embed\/|watch\?\S*v=|v\/)?(\d*)/;
// when cookies are blocked then iframe has attribute data-cookieblock-src in the other way has src
var iframeDataCookieBlockSrc = $(this).attr('data-cookieblock-src');
var iframeSrc = $(this).attr('src');
if(iframeDataCookieBlockSrc) {
if (iframeDataCookieBlockSrc.match(regexVimeo)) {
$(".hero-banner").css("display", "block");
$(".youtube-banner").css("display", "none");
}
}
if(iframeSrc) {
if (iframeSrc.match(regexVimeo)) {
$(".hero-banner").css("display", "none");
$(".youtube-banner").css("display", "block");
}
}