mylink (the button's this) isn't a string, so you try to open mylink.href:

if (typeof(mylink) == 'string')
  href = mylink;
else 
  href = mylink.href;

But buttons don't have href properties, so it's as if you wrote:

window.open(undefined, 'about', 'width=400,height=200,scrollbars=yes');

which opens a blank page, as expected. If you want to open the same page as the link, use:

onclick="popup('newpopup.html', 'about');"
Answer from Paul Roub on Stack Overflow
🌐
W3Schools
w3schools.com › howto › howto_js_popup.asp
How To Create Popups
Learn how to create popups with CSS and JavaScript. Click me to toggle the popup! A Simple Popup! ... <div class="popup" onclick="myFunction()">Click me!
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-open-a-popup-on-click-using-javascript
How to Open a Popup on Click using JavaScript ? - GeeksforGeeks
August 5, 2025 - In this approach, we are using ... and popup dialog elements. The popupFn() and closeFn() functions dynamically set the display property to 'block' for opening and 'none' for closing, performing a popup effect on button ...
People also ask

Is Popupsmart Compatible with CMS to Display Popup Campaign?
Yes, it is. When you decide to create and publish your popup, all you need to do is customize your campaign and make sure that your embed code is working properly on your website.
🌐
popupsmart.com
popupsmart.com › popupsmart conversion rate optimization & digital marketing blog › how to build a popup that opens on a button click
How to Build a Popup That Opens on a Button Click
How Can I Ensure a Seamless UX with Popups?
Focusing on the timing and relevance of your popups is essential. Utilize the features to allow users to initiate interactions when they are ready, reducing the likelihood of interrupting their browsing experience.
🌐
popupsmart.com
popupsmart.com › popupsmart conversion rate optimization & digital marketing blog › how to build a popup that opens on a button click
How to Build a Popup That Opens on a Button Click
Can I Track the Performance of My Popups?
Yes, Popupsmart provides Leads and Analytics pages, where you can monitor metrics such as conversion rates, click-through rates, and engagement data to assess the effectiveness of your popups and make data-driven improvements.
🌐
popupsmart.com
popupsmart.com › popupsmart conversion rate optimization & digital marketing blog › how to build a popup that opens on a button click
How to Build a Popup That Opens on a Button Click
🌐
PopupSmart
popupsmart.com › popupsmart conversion rate optimization & digital marketing blog › how to build a popup that opens on a button click
How to Build a Popup That Opens on a Button Click
January 26, 2024 - Create an event listener for the button click event, and use it to toggle the visibility of the popup by changing its display property. You can use JavaScript to add the functionality to open the modal when the button is clicked and to close ...
🌐
CodePen
codepen.io › marine-fraysse › pen › eYmBEvQ
Pop-up on Button Click
<button class="button" href="#" onclick="show('popup')">Button</button> <!-- This is what will be included inside the popup --> <div class="popup" id="popup"> <p>This is a popup!</p> <p>Overlay uses <b>:before</b> and <b>:after</b> ...
Find elsewhere
Top answer
1 of 4
9

Here is a fiddle that actually does what you want - http://jsfiddle.net/WGPhG/6/

JS

function popUp(){
    var popup = document.createElement('div');
    popup.className = 'popup';
    popup.id = 'test';
    var cancel = document.createElement('div');
    cancel.className = 'cancel';
    cancel.innerHTML = 'close';
    cancel.onclick = function (e) { popup.parentNode.removeChild(popup) };
    var message = document.createElement('span');
    message.innerHTML = "This is a test message";
    popup.appendChild(message);                                    
    popup.appendChild(cancel);
    document.body.appendChild(popup);
}

NOTES

To set the class on an element you use element.className instead of element.class. For the onclick event handler on the cancel element, it is better to directly assign the onclick handler with an anonymous function that does what you need as in my example above.


EDIT (More Efficient Way)

This is actually a much better of getting the results that you want because there is no overhead involved with recreating the elements every time the popup is shown. Fiddle - http://jsfiddle.net/WGPhG/7/

CSS

.popup
{
    position:absolute;
    top:0px;
    left:0px;
    margin:100px auto;
    width:200px;
    height:150px;
    font-family:verdana;
    font-size:13px;
    padding:10px;
    background-color:rgb(240,240,240);
    border:2px solid grey;
    z-index:100000000000000000;
    display:none
}

.cancel
{
    display:relative;
    cursor:pointer;
    margin:0;
    float:right;
    height:10px;
    width:14px;
    padding:0 0 5px 0;
    background-color:red;
    text-align:center;
    font-weight:bold;
    font-size:11px;
    color:white;
    border-radius:3px;
    z-index:100000000000000000;
}

HTML

<button onClick="openPopup();">click here</button>
<div id="test" class="popup">
    This is a test message
    <div class="cancel" onclick="closePopup();"></div>
</div>

JS

function openPopup() {
    document.getElementById('test').style.display = 'block';
}

function closePopup() {
    document.getElementById('test').style.display = 'none';
}
2 of 4
1

Try this update on JSFiddle

Changed :

  1. Center page (fixed).
  2. effect (fadein and fadeout)

HTML

<button onClick="openPopup();">click here</button>
<div id="test" class="popup" style="display:none;">
    This is a test message
    <div class="cancel" onclick="closePopup();"></div>
</div>

CSS

.popup {
    position:fixed;
    top:0px;
    left:0px;
    bottom:0px;
    right:0px;  
    margin:auto;
    width:200px;
    height:150px;
    font-family:verdana;
    font-size:13px;
    padding:10px;
    background-color:rgb(240,240,240);
    border:2px solid grey;
    z-index:100000000000000000;
}

.cancel {
    display:relative;
    cursor:pointer;
    margin:0;
    float:right;
    height:10px;
    width:14px;
    padding:0 0 5px 0;
    background-color:red;
    text-align:center;
    font-weight:bold;
    font-size:11px;
    color:white;
    border-radius:3px;
    z-index:100000000000000000;
}

.cancel:hover {
    background:rgb(255,50,50);
}

JS

function openPopup() {
    //document.getElementById('test').style.display = 'block';
   $('#test').fadeIn(1000);
}

function closePopup() {
    //document.getElementById('test').style.display = 'none';
    $('#test').fadeOut(500);
}
🌐
C# Corner
c-sharpcorner.com › blogs › javascriptopen-new-popup-window-on-button-click-event1
Javascript-Open new Popup Window on button click event
April 29, 2020 - <script type="text/javascript"> ... To Open : <input type="text" name="txtpath"/> <input type="button" value="Open" name="btnOpenPopup" onClick="OpenNewWindow(txtpath.value)" /> </FORM> </body> </html> People also reading ...
🌐
Stack Exchange
gis.stackexchange.com › questions › 332444 › leaflet-js-open-popup-on-button-click
javascript - Leaflet JS - open popup on button click - Geographic Information Systems Stack Exchange
In your event listener function, you can pass the event and then call event.stopPropagation() to avoid clicks on the map beneath the button. :) ... You need to remove the map click listener from your added node. This should make sure a map click is not recorded when you click the html node you added. resume.onAdd = function(map) { this._div = L.DomUtil.create('div', 'resume'); this._div.innerHTML = title + '<br>' + description; # This is your missing row########################### L.DomEvent.disableClickPropagation(this._div); ############################################## return this._div; };
🌐
Linux Hint
linuxhint.com › open-a-popup-window-in-javascript-using-onclick
How to Open a Popup Window in JavaScript Using Onclick?
Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
W3docs
w3docs.com › javascript
How to Create a Popup Form Using JavaScript
function openForm() { ... modal) { closeForm(); } } It is not too difficult to have several Popup Forms use the data-*global attribute....
Top answer
1 of 1
1

Changes

div#main has been changed to dialog#main. <dialog> is a built-in HTML tag and is normally hidden unless it has the open attribute or has been opened by one of it's methods either .showModal() or .show(). .showModal() is what you'd be interested in because there's a special CSS property that only applies to fullscreen backgrounds or a dialog's backdrop -- it's appropriately called ::backdrop (see CSS of example).

Added 2 buttons one to close the <dialog> and another to open it.

Added a flag which is true to start out at then once the <dialog> opens that button generating function starts and then that flag is set to false. I had to stop it because I'm not sure if you wanted it to keep making buttons every time the <dialog> opens or not. Anyways, the flag is easily removed or you could adjust the conditions in which the flag is set to.

const modal = document.querySelector(".smallFrame");
const show = document.querySelector('.show');
const hide = document.querySelector('.hide');

let flag = true;
show.onclick = popUp;
hide.onclick = e => modal.close();

function popUp(e) {
  modal.showModal();
 
  if (!flag) {
    return;
  }
  let tempCounterBtn = 0;
  for (let i = 0; i < 2; i++) {
    let newDiv = document.createElement("div");
    newDiv.id = "div-" + (i + 1);
    modal.appendChild(newDiv);
    for (let x = 0; x < 6; x++) {
      let btn = document.createElement("button");
      btn.id = "button-" + (tempCounterBtn + 1);
      tempCounterBtn++;
      newDiv.appendChild(btn);
    }
  }
  flag = false;
}
html {
  font: 300 2ch/1.25 'Segoe UI'
}

body {
  display: flex;
  justify-content: center;
  margin: 1.2em;
}

button {
  background: rgba(0, 0, 0, 0);
  color: #a5afaa;
  border: 1px solid white;
  border-radius: .6em;
  padding: 3em;
}

button:hover {
  border-color: #fff8cc;
  box-shadow: 0em 0em 1em 0em yellow;
}

#main {
  border: solid 2px #939388;
  border-radius: 10px;
  background-color: #0f0f3de8;
  box-shadow: 0 0.1em 0.3em 0.1em rgba(0, 0, 0, 0.6);
}

#main::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.inner {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  padding: 20px;
}

.smallFrame {
  border: solid 2px #939388;
  border-radius: 10px;
  background-color: #0f0f3de8;
  box-shadow: 0 0.1em 0.3em 0.1em rgba(0, 0, 0, 0.6);
  width: 400px;
  height: 250px;
}

.hide {
  padding: 0.5em;
  float: right;
}

.show:hover,
.hide:hover {
  border-color: #fff8cc;
  box-shadow: 0em 0em 1em 0em lime;
  cursor: pointer;
}
<div id="main">
  <div id="inner-15" class="inner"></div>
</div>
<button class='show'>Show</button>

<dialog class="smallFrame">
  <button class='hide'>Close</button>
</dialog>

🌐
WisePops
wisepops.com › blog › popup-on-a-button-click
How to make a popup that opens on a button click [+examples]
Learn how to create a popup that opens on a button click, or an on-click popup form.
Top answer
1 of 2
1

You could use jquery ui dialog, or, if you want to get more ...fancy, you could use fancybox:

$(document).ready(function() {
    $("a#inline").fancybox({
		'hideOnContentClick': true
	});
  
  
});
.btn{
  border: 1px solid #006; 
  color:#01ACEE; 
  font: bold 16px Tahoma; 
  border-radius:7px; 
  padding:4px;
  
  }
<link rel="stylesheet" href="http://dodsoftware.com/sotests/fancy/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="http://dodsoftware.com/sotests/fancy/jquery.fancybox-1.3.4.js"></script>
<script type="text/javascript" src="http://dodsoftware.com/sotests/fancy/jquery.easing-1.3.pack.js"></script>
<script type="text/javascript" src="http://dodsoftware.com/sotests/fancy/jquery.mousewheel-3.0.4.pack.js"></script>

<a id="inline" class="btn" href="#data">My Button</a>

<div style="display:none">
    <div id="data">
    <img alt="" src="http://farm9.staticflickr.com/8366/8483546751_86494ae914_m.jpg"><br>
        <h3>My Cool Title</h3>
        <p>Put your cool item descrtiption here</p>
   </div>
</div>

2 of 2
1

You can try jquery ui dialog like,

HTML

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div id="dialog" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>

SCRIPT

$(function() {
    $( "#dialog" ).dialog();
});

Also you can try bootstrap modal