Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Popup in browser, new tab when mobile/blocked
<!DOCTYPE html>
<html>
<head>
<title>Popup test</title>
</head>
<body>
<button class="js-button">Open popup</button>
</body>
<script>
const btn = document.querySelector('.js-button');
const width = 440;
const height = 584;
const options = [
'resizable=yes',
'scrollbars=yes',
'titlebar=yes',
`width=${width}`,
`height=${height}`,
`top=${(window.outerHeight / 2) - height / 2}`,
`left=${(window.outerWidth / 2) - width / 2}`
];
btn.addEventListener('click', () =>
window.open(
'http://127.0.0.1:8082/src/popup',
"_blank",
options.join(',')
)
)
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment