Here's how I survived:
Code: Select all
//This function loads the popup from the main window:
function PopUpPerm(ID){
<?php
if ($_GET['BrowserIsGecko']){
?>
window.open('popup-perm.php?ID=' + ID, "joja", "dependent,height=1000,width=1000,scrollbars")
<?php
}else{
?>
window.showModalDialog('popup-perm.php?ID=' + ID, "joja", "dialogWidth:300px; dialogHeight:600px;resizable:yes;scrollbars:yes")
<?php
}
?>
}
And here's the popupwindow code:
Code: Select all
<html>
<head>
<SCRIPT>
function InitPage(){
Resize()
window.focus()
}
function min(a,b){
return a < b ? a : b
}
var padding = 50
function Resize(){
<?php
if ($BrowserIsGecko){
?>
var tableWidth = document.defaultView.getComputedStyle(document.getElementById('Table3'),null).getPropertyValue("width")
tableWidth = Number(tableWidth.substr(0,tableWidth.length-2))
var windowWidth = window.outerWidth
var clientWidth = window.innerWidth
var tableHeight = document.defaultView.getComputedStyle(document.getElementById('Table'),null).getPropertyValue("height")
tableHeight = Number(tableHeight.substr(0,tableHeight.length-2))
var windowHeight = window.outerHeight
var clientHeight = window.innerHeight
var windowCX = tableWidth + (windowWidth - clientWidth) + padding
var windowCY = min(tableHeight + (windowHeight - clientHeight) + padding ,window.screen.availHeight )
window.resizeTo( windowCX, windowCY);
window.moveTo((window.screen.availWidth - windowCX) / 2 ,(window.screen.availHeight - windowCY) / 2)
<?php
}else{
?>
oRcts = document.getElementById('Table3').getClientRects();
var tableWidth = oRcts[0].right - oRcts[0].left
var windowWidth = window.dialogWidth
windowWidth = Number(windowWidth.substr(0,windowWidth.length-2))
var clientWidth = document.body.offsetWidth
oRcts = document.getElementById('Table').getClientRects();
var tableHeight = oRcts[0].bottom - oRcts[0].top
var windowHeight = window.dialogHeight
windowHeight = Number(windowHeight.substr(0,windowHeight.length-2))
var clientHeight = document.getElementById('Body').offsetHeight
var windowCX = tableWidth + (windowWidth - clientWidth) + padding
var windowCY = min(tableHeight + (windowHeight - clientHeight) + padding,window.screen.availHeight )
window.dialogWidth = windowCX + 'px'
window.dialogHeight = windowCY + 'px'
window.dialogLeft = (window.screen.availWidth - windowCX) / 2 + 'px'
window.dialogTop = (window.screen.availHeight - windowCY) / 2 + 'px'
<?php
}
?>
}
</SCRIPT>
</head>
<body onload="InitPage()" id="Body">
<table id="Table">
<tr>
<td>
<table id="Table3">
<tr><td>[Content]</td></tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Yepp! Lots of characters! Optimize it for me someone! I'm too tired of it to do it right now.
Here's what it does:
It fits the popupwindow around the content nicely, and the usage of that "min"-function keeps it inside the screen in case of very tall content.
The code works both in Mozilla, NS7 and IE6.