As you mention, the IE modal dialog does not quite work like a normal browser window. By trying various things, you can sort of reverse engineer how it works and pull some compensating tricks. You stated that you have control of the HTML, that it's OK to use Javascript, so here's what I came up with.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Blarg 2</title>
<style type='text/css'>
body { margin: 20px; width:1px}
#test { background: red; height: 500px; }
</style>
<script>
window.onload=windowResized;
window.onresize=windowResized;
function windowResized()
{
var cw = document.documentElement.clientWidth ;
var margin = 20 ;
document.getElementById("test").style.width=(cw-2*margin)+"px" ;
}
</script>
</head>
<body>
<div id="test" >
<input type='button'
onclick="javascript:window.showModalDialog('test.html', window, 'dialogWidth: 300px; resizable: yes;');" />
There is a bit more than meets the eye here.
</div>
</body>
</html>
The crux of this code is to resize the width of the <div>
that contains the content. Ordinarily this width would be the width of the window (less the margins), but in the case of the IE modal dialog, we should use the width of the window less the scrollbar width. This is given to us by document.documentElement.clientWidth
. We do this resizing when the dialog is loaded and whenever it is resized.
The initial width of the body (upon load, but before we resize the <div>
)seems to confuse IE, so we set it to 1px
. So that's a 'magic number' in the code, as is the var margin = 20 ;
, which must match the CSS margin
. I've also set the div height
to 500px
so that it's easier to see what happens when the vertical scroll bar is on or off.
I've tested this in IE6/7/8 and Chrome on Windows XP, and FF3.6 and Chrome on the Mac. I've made the code here as simple as possible, so if the contents of your div
get more complicated hopefully you'll be able to modify the Javascript as necessary. Hope this works for you.