Last active
May 17, 2020 16:23
-
-
Save iprodev/e5ce3c9482fe24b51da622107abfd083 to your computer and use it in GitHub Desktop.
Opens a new browser window
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
/** | |
* Opens a new browser window | |
* @param {String} url The url of the window to open | |
* @param {String} name The name of this window | |
* @param {Number} width Window width | |
* @param {Number} height Window height */ | |
const popUpWindow = (url, name, width, height)=> { | |
// Center the window | |
let _width = Math.min(width || 640, screen.availWidth), | |
_height = Math.min(height || 480, screen.availHeight), | |
left = (screen.width / 2) - (_width / 2), | |
top = (screen.height / 2) - (_height / 2); | |
let options = [ | |
'width=' + _width, | |
'height=' + _height, | |
'left=' + left, | |
'top=' + top, | |
'resizable=0', | |
'menubar=0', | |
'centerscreen=1', | |
'location=0', | |
'scrollbars=0', | |
'toolbar=0', | |
'status=0' | |
]; | |
const newwindow = window.open(url, name, options.join(',')); | |
if (window.focus) { | |
newwindow.focus(); | |
} | |
return newwindow; | |
}; | |
export default popUpWindow; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment