JSFiddle - React, Tailwind, and code Playground
by Scott Kaye
HTML
<button>Open Popup</button>
JavaScript
console.clear();
function popup(url) {
var width = 1280;
var height = 720;
var left = (screen.width - width) / 2;
var top = (screen.height - height) / 2;
var params = 'width=' + width + ', height=' + height;
params += ', top=' + top + ', left=' + left;
params += ', directories=no';
params += ', location=no';
params += ', menubar=no';
params += ', resizable=yes';
params += ', scrollbars=yes';
params += ', status=no';
params += ', toolbar=no';
newwin = window.open(url, 'windowname4', params);
console.log("newwin is now", newwin);
if (window.focus) {
newwin.focus();
}
}
// Will not work, error in developer console because newwin fails
setTimeout(function() {
popup('https://google.ca');
}, 1000);
// Will work
document.querySelector("button").onclick = function() {
popup("https://google.ca");
};