I would not recomend you to use document.write as others suggest, because if you will open such window twice your HTML will be duplicated 2 times (or more).

Use innerHTML instead

var win = window.open("", "Title", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=200,top="+(screen.height-400)+",left="+(screen.width-840));
win.document.body.innerHTML = "HTML";
Answer from artnikpro on Stack Overflow
🌐
WisePops
wisepops.com › blog › html-popup
How to Create an HTML Popup [CSS, Javascript]
Create a separate CSS file (styles.css) to define the visual style of your popup window. Customize dimensions, colors, and animations to match your website's design (you can add color codes to the code below) ... Develop the JavaScript functionality in a separate file (script.js) to control the popup's behavior. Use event listeners to handle opening and closing the popup. document.addEventListener('DOMContentLoaded', function () { const popupOverlay = document.getElementById('popupOverlay');
🌐
JavaScript.info
javascript.info › tutorial › frames and windows
Popups and window methods
Help to translate the content of this tutorial to your language! ... A popup window is one of the oldest methods to show additional document to user. ... …And it will open a new window with given URL.
🌐
freeCodeCamp
forum.freecodecamp.org › html-css
Pop up window with HTML CSS JS - HTML-CSS - The freeCodeCamp Forum
April 19, 2021 - Hi guys, can you help me out, please, on how to create a pop up window like the one that welcomes you at t the following site: https://coolors.co/ . The idea will be displaying a pic when you arrive on the site (i was thinking about using js or jquery, maybe the: .onload or maybe $( document ).ready()) with black fading background and when you click on an “X” top right of the pic or anywhere else but on the image, the div disappear and you’ll see the body content.
🌐
PureBasic
purebasic.fr › home › board index › miscellaneous › off topic
Help with Javascript / html popup window - PureBasic Forums - English
It opens the popup window and fills it with popup.html --> <html> <head> <title>Popup test</title> </head> <script language='javascript' type='text/javascript'> function popupwindow(url, windowName, w, h) { const x = window.top.outerWidth / 2 + window.top.screenX - ( w / 2); const y = window.top.outerHeight / 2 + window.top.screenY - ( h / 2); window.open(url,windowName,'width='+w+',height='+h+',top='+y+',left='+x+''); } </script> <script language='javascript' type='text/javascript'> async function dopopup() { popupwindow('popup.html', 'Level', 200, 300); } </script> <body> Click below to trigger popup window<br> <br> <button id='levelbtn'>Popup</button> <script language="javascript" type="text/javascript"> document.getElementById("levelbtn").addEventListener("click", dopopup); </script> </body> </html>
🌐
HTML.com
html.com › javascript › popup-windows
Popup Windows Made Easy: Here's The JavaScript Code To Copy And Paste »
March 19, 2020 - This tutorial will walk you step-by-step through creating popup windows, including giving you a complete set of copy-and-paste JavaScript code. We’ll start with a basic example, showing the main pieces to a popup. Then we’ll show the techniques for targeting a link inside the popup back to the main page.
🌐
W3Schools
w3schools.com › howto › howto_js_popup.asp
How To Create Popups
Learn how to create popups with CSS and JavaScript.
Find elsewhere
🌐
DHTMLX
dhtmlx.com › docs › products › dhtmlxPopup
JavaScript Popup Box - dhtmlxPopup
dhtmlxPopup is a free JavaScript component for displaying a neat popup box with any custom HTML content in it.
🌐
TextFixer
textfixer.com › html › javascript-pop-up-window.php
Create a Javascript Popup Window
Using this popup window generator script lets you control the pop-up window size and appearance, along with the option to make the pop up resizable or not. All the necessary HTML code is generated by this tool so all you have to do is copy and paste the script. So go ahead and generate some popup window code for yourself. I've added some observations about current cross browser support for pop-up windows at the bottom of the page.
🌐
W3Schools
w3schools.com › js › js_popup.asp
JavaScript Popup Boxes
An alert box is often used if you want to make sure information comes through to the user. When an alert box pops up, the user will have to click "OK" to proceed. ... The window.alert() method can be written without the window prefix.
🌐
Moodle
moodle.org › mod › forum › discuss.php
Moodle in English: Help with sample HTML file for popup window content in a Lesson. | Moodle.org
It's been a couple of days, but hope you can still take a look. I am attaching 3 images of the screens and one file containing the CSS and HTML. After quite a bit of frustration trying to get the <div>s to work with javascript, I took a different approach relying completely on CSS and HTML using an unordered list.
🌐
Your HTML Source
yourhtmlsource.com › html source › javascript › popup windows | open new customised windows with javascript
Popup Windows | open new customised windows with JavaScript
November 17, 2025 - You don't need to create a whole new page for each of your popups, and so the popup content is already loaded when the main page is. First, let's » generate a page. function dirtypop() { var generator=window.open('','name','height=400,width=500'); generator.document.write('<html><head><title>Popup</title>'); generator.document.write('<link rel="stylesheet" href="style.css">'); generator.document.write('</head><body>'); generator.document.write('<p>This page was generated by the main window.</p>'); generator.document.write('<p><a href="javascript:self.close()"> Close</a> the popup.</p>'); generator.document.write('</body></html>'); generator.document.close(); }
Top answer
1 of 2
8

Here is a simple solution that will allow you to fetch value from opened window. All you need is to inject JavaScript code into opened window that will interact with the parent window using window.opener:

HTML

<input id="value" />
<button onclick="openWindow();">Open</button>

JavaScript

function openWindow() {
    var i, l, options = [{
       value: 'first',
       text: 'First'
    }, {
       value: 'second',
       text: 'Second'
    }],
    newWindow = window.open("", null, "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");  

    newWindow.document.write("<select onchange='window.opener.setValue(this.value);'>");
    for(i=0,l=options.length; i<l; i++) {
        newWindow.document.write("<option value='"+options[i].value+"'>");  
        newWindow.document.write(options[i].text);  
        newWindow.document.write("</option>");
    }
    newWindow.document.write("</select>");
}

function setValue(value) {
    document.getElementById('value').value = value;
}

Working example here: http://jsbin.com/uqamiz/1/edit

2 of 2
2

The easiest way is to have a superimposed div with a a high z-index, with transparent background acting as an overlay. You could then have another div which is centered above the overlay(with higher z-index) and containing the list markup

CSS

#shim {
opacity: .75;
filter: alpha(opacity=75);
-ms-filter: "alpha(opacity=75)";
-khtml-opacity: .75;
-moz-opacity: .75;
background: #B8B8B8;
position: absolute;
left: 0px;
top: 0px;
height: 100%;
width: 100%;
z-index:990
}

#msgbx {
position: absolute;
left: 50%;
top: 50%;
height: 150px;
width: 350px;
margin-top: -75px;
margin-left: -175px;
background: #fff;
border: 1px solid #ccc;
box-shadow: 3px 3px 7px #777;
-webkit-box-shadow: 3px 3px 7px #777;
-moz-border-radius: 22px;
-webkit-border-radius: 22px;
z-index:999
}

HTML

<div id="shim"></div>
<div id="msgbx">inject list markup here</div>

To show popup

document.getElementById('shim').style.display=document.getElementById('msgbx').style.display ="block";

To Hide

document.getElementById('shim').style.display=document.getElementById('msgbx').style.display ="none";
🌐
Google Groups
groups.google.com › a › chromium.org › g › chromium-extensions › c › BTUBPMBg-W4
Opening popup.html from within content.js
1. content.js tells the background script to create a popup window with an extension URL, using message passing.
🌐
Mobiscroll
demo.mobiscroll.com › javascript › popup
Javascript Popup Examples | Mobiscroll
Pop-over examples with customizable content, button configuration and behavior. For vanilla JS to use everywhere. Last update: Feb 24, 2026
🌐
MakeUseOf
makeuseof.com › home › programming › create a popup window using html, css, and javascript
Create a Popup Window Using HTML, CSS, and JavaScript
May 13, 2023 - You can create popup windows with HTML, CSS, and JavaScript. Use the following guide to create and style a popup window from scratch. It makes your website interactive and creates great user experiences. Let's write some HTML code that has a hidden modal window that pops up when you click a button. In this case, you will display the meaning of the word Hello! The popup window will have a heading and some content...
🌐
Picreel
picreel.com › home › blog › popup implementation › html popup message: quick methods with codes & steps
HTML Popup Message Guide: HTML, CSS, and JavaScript (+Hack)
October 14, 2025 - Here are the steps to build an HTML popup page using HTML, CSS, and JavaScript: ... To begin with, create the structure of the HTML popup box. Here, you can include the HTML popup message, title, overlay, and close button.
🌐
QuirksMode
quirksmode.org › js › popup.html
JavaScript - Popups
Usually the location is this page, popup.html, that's because the browser sees the popup as a kind of extended part of this page. I noticed this problem because a colleague of mine wanted to use this sort of script for making a printer friendly version of a page. Write the content into a popup, with minimal markup, and then let the user press 'Print'.