Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Using iFrames</title>
</head>
<body>
<p><button id="btn">Click to Pause/Play</button></p>
<iframe id="frm" src="vid-frame.html" height="300px" width="500px"></iframe>
<script>
document.addEventListener("DOMContentLoaded", () => {
let frm = document.getElementById("frm");
console.log(frm);
frm.addEventListener("load", ev => {
console.log(ev.target.contentDocument);
let vid = ev.target.contentDocument.getElementById("player");
console.log(vid);
let btn = document.getElementById("btn");
btn.addEventListener("click", ev => {
if (vid.paused) {
vid.play();
} else {
vid.pause();
}
});
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.