Created
March 1, 2022 00:46
-
-
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().
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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