Skip to content

Instantly share code, notes, and snippets.

@robdecker
Last active November 2, 2019 01:54
Show Gist options
  • Save robdecker/15415f6d161310654ac2 to your computer and use it in GitHub Desktop.
Save robdecker/15415f6d161310654ac2 to your computer and use it in GitHub Desktop.
[Open a popup window, centered in parent] #js #jquery
function OpenWindow(url, width, height, name) {
var screenLeft = 0;
var screenTop = 0;
if (!name) {
name = 'MyWindow';
}
if (!width) {
width = 600;
}
if (!height) {
height = 600;
}
if (typeof window.screenLeft !== 'undefined') {
screenLeft = window.screenLeft;
screenTop = window.screenTop;
}
else if (typeof window.screenX !== 'undefined') {
screenLeft = window.screenX;
screenTop = window.screenY;
}
var features_dict = {
toolbar: 'no',
location: 'no',
directories: 'no',
left: screenLeft + ($(window).width() - width) / 2,
top: screenTop + ($(window).height() - height) / 2,
status: 'yes',
menubar: 'no',
scrollbars: 'yes',
resizable: 'no',
width: width,
height: height
};
features_arr = [];
for (var k in features_dict) {
features_arr.push(k+'='+features_dict[k]);
}
features_str = features_arr.join(',')
var win = window.open(url, name, features_str);
win.focus();
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment