To create a popup page/window on the screen. Please follow the following script-
The below code will work only on hyperlink
<a href="popup.php"target="popup" onclick="window.open('database.php','popup','width=300,height=200'); return false;">Click for pop-up page/window</a>
And for open popup window on center of screen on click on any hyperlink, then-
<script>
function CenteredPopup(url, title, w, h) { var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
</script>
<a onclick="CenteredPopup('popuppage.html', 'popup title',350,350);" href="javascript:void(0);">CLICK for centered pop up</a>
If you are using a button to popup any page, then-
If you want to open this window on the non-center of the screen then-
<script>
function PopupnoncentWin(pageURL, pageTitle,
popupWinWidth, popupWinHeight) {
var left = (screen.width ) ;
var top = (screen.height ) ;
var myWindow = window.open(pageURL, pageTitle,
'resizable=yes, width=' + popupWinWidth
+ ', height=' + popupWinHeight + ', top='
+ top + ', left=' + left);
}
</script>
<button onclick = "PopupnoncentWin('popuppage.html',
'Pop-Up title', 200, 200);">
Popup example
</button>
If you want to open this window on the center of the screen then-
<script>
function PopupcenWin(pageURL, pageTitle,
popupWinWidth, popupWinHeight) {
var left = (screen.width - popupWinWidth) / 2;
var top = (screen.height - popupWinHeight) / 4;
var myWindow = window.open(pageURL, pageTitle,
'resizable=yes, width=' + popupWinWidth
+ ', height=' + popupWinHeight + ', top='
+ top + ', left=' + left);
}
</script>
<button onclick = "PopupcenWin('popcenterpage.html',
'Popup page title', 200, 250);">
pop up centered example
</button>