Last active
May 28, 2021 04:32
-
-
Save dinkydani/f9d8dd08b0e9a5299e11cd2a1f67f81d to your computer and use it in GitHub Desktop.
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
let windowObjectReference = null; | |
let previousUrl = null; | |
const openSignInWindow = (url, name) => { | |
// remove any existing event listeners | |
window.removeEventListener('message', receiveMessage); | |
// window features | |
const strWindowFeatures = | |
'toolbar=no, menubar=no, width=600, height=700, top=100, left=100'; | |
if (windowObjectReference === null || windowObjectReference.closed) { | |
/* if the pointer to the window object in memory does not exist | |
or if such pointer exists but the window was closed */ | |
windowObjectReference = window.open(url, name, strWindowFeatures); | |
} else if (previousUrl !== url) { | |
/* if the resource to load is different, | |
then we load it in the already opened secondary window and then | |
we bring such window back on top/in front of its parent window. */ | |
windowObjectReference = window.open(url, name, strWindowFeatures); | |
windowObjectReference.focus(); | |
} else { | |
/* else the window reference must exist and the window | |
is not closed; therefore, we can bring it back on top of any other | |
window with the focus() method. There would be no need to re-create | |
the window or to reload the referenced resource. */ | |
windowObjectReference.focus(); | |
} | |
// add the listener for receiving a message from the popup | |
window.addEventListener('message', event => receiveMessage(event), false); | |
// assign the previous URL | |
previousUrl = url; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment