Browser Popup Window Generator

HTML Javascript Popup Window Generator

Demo Popup Window
Demo
1

Enter Popup Window URL And Size Name

2

Preview

Paste this code between the body tag where you want it to appear
JavaScript
Paste this code between the body tag, at the bottom of the page

Open links in a single popup window tab

HTML
<a href="https://www.google.com/" target="popupWindow">Google</a>
<a href="https://www.youtube.com/" target="popupWindow">Youtube</a>
<a href="https://www.html-code-generator.com/" target="popupWindow">HTML</a>
JavaScript
(() => {
    let popupWindow = null;
    let previousURL;
    let windowSize = "width=800,height=600,left=0,top=0";
    let windowName = "singleWindow";

    const OpenPopupSingleTab = (url) => {
        if (popupWindow === null || popupWindow.closed) {
            popupWindow = window.open(url, windowName, windowSize);
        } else if (previousURL !== url) {
            popupWindow = window.open(url, windowName, windowSize);
            popupWindow.focus();
        } else {
            // If the URL is already open, focus the window without reloading
            popupWindow.focus();
        }
        previousURL = url;
    };

    const links = document.querySelectorAll("a[target='popupWindow']");
    for (const link of links) {
        link.addEventListener("click", function(event) {
            OpenPopupSingleTab(this.href);
            event.preventDefault();
        }, false);
    }
})();
Try it Yourself