In 2022 ish I used to be able to close a youtube window with javascript
var openedWindow;
function openWindow() {
openedWindow = window.open('https://www.youtube.com/watch?
v=TC1Vfoq3PvU&ab_channel=Historyboy87','_blank', 'location=yes,height=400,width=400,scrollbars=yes,status=yes');
}
function closeOpenedWindow() {
openedWindow.close();
}
This no longer works. Have tried in Chrome, Firefox and Edge. It will close other websites but not youtube.
You can only EMBED Youtube videos in an iframe and it'll only work if they're not very popular (ie: most music videos with tons of views get blocked).
Here's how I do it, however... it is based on data:text/html to create a "openable" page on the fly and I'm not sure if this still works in the latest browser versions!
It may have been dropped for "security" reasons (read stupid reasons) like so many other wonderful things; and the reason I use a custom browser with older engines. :)
Anyway, in case it does work in the latest commercial browsers, here's how to do it...
NB: Or use window.open() with the URL.
Update:
Here's a modern version using a blob...