Skip to content

Instantly share code, notes, and snippets.

@zadeviggers
Created March 1, 2022 00:46
Show Gist options
  • Save zadeviggers/308cd255e9328feab3766cbea4ebd02a to your computer and use it in GitHub Desktop.
Save zadeviggers/308cd255e9328feab3766cbea4ebd02a to your computer and use it in GitHub Desktop.
Opens a login window popup in the center of the screen using window.open().
const popupWidth = 400;
const popupHeight = 600;
// Maths "borrowed" from the smart folks at Auth0 (https://github.com/auth0/auth0-spa-js/blob/451956f5615bdd7e8fe3c313dbe30d1e31b855f1/src/utils.ts#L92)
const popupLeft = window.screenX + (window.innerWidth - popupWidth) / 2;
const popupTop = window.screenY + (window.innerHeight - popupHeight) / 2;
// The window.open call needs to be called inside an event listener for a user-created action like a click
document.addEventListener("click", ()=>window.open("https://exmaple.com?in_popup=ye", "my-auth-popup", `popup,width=${popupWidth},height=${popupHeight},left=${popupLeft},top=${popupTop}`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment