<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Always Visible Controls YouTube Ad</title>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
.ad-container {
width: 300px;
height: 250px;
position: relative;
cursor: pointer;
overflow: hidden;
}
.ad-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 10;
}
iframe {
width: 100%;
height: 100%;
border: none;
z-index: 1;
}
</style>
<script>
var clickTag = "https://www.google.com/";
function bindEvent(element, eventName, eventHandler) {
if (element.addEventListener) {
element.addEventListener(eventName, eventHandler, false);
} else if (element.attachEvent) {
element.attachEvent("on" + eventName, eventHandler);
}
}
function postPauseToIframe() {
const iframe = document.getElementById('youtube-video');
iframe.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
}
</script>
</head>
<body>
<div class="ad-container" id="clickable-ad">
<iframe
id="youtube-video"
src="https://www.youtube.com/embed/vsZBIkR1QEA?enablejsapi=1&autoplay=1&mute=1&controls=1&loop=1&playlist=vsZBIkR1QEA"
title="YouTube video player"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerpolicy="strict-origin-when-cross-origin"
allowfullscreen>
</iframe>
<div class="ad-overlay" id="overlay"></div>
</div>
<script>
// Listen for click events on the overlay
document.getElementById("overlay").addEventListener("click", function (e) {
const rect = this.getBoundingClientRect();
const clickX = e.clientX - rect.left;
// If click is in the middle 50px horizontally (e.g. 125px to 175px), pause video
if (clickX >= 125 && clickX <= 175) {
postPauseToIframe();
} else {
window.open(clickTag, "_blank");
}
});
// Listen for dynamic clickTag messages
bindEvent(window, "message", function (e) {
const message = e.data;
if (typeof message === "string" && message.includes("googleclicktag")) {
if (message.split("_")[0] === "googleclicktag") {
clickTag = message.substr(15);
}
}
});
</script>
</body>
</html>
24
9
968KB
3636KB
281.0ms
ms
3,664.0ms