MM wrote:
I am using the following code to display an image in a seperate
window.
<form>
<input type=button
onClick='window.open("image1.jpg","","width=260,he ight=260,resizable=0,border=0")'
value=Shhow Picture'>
</form>
I want the window to be the exact size of the image so I set the width
and height of the window the same as the width & height of the image.
You can't reliably do this for all browsers. Some automatically put a
margin of 20px or so on all <body> tags by default. Some also add it
when showing just an image, but others not. Safari adds it when
showing a page, but not when showing an image.
Even if you manage to set the margin to 0, some browsers will leave a
border on the other side of the image (IE on Mac). So the simplest
solution is to put all your images into HTML documents and load those
(setting margin to 0).
Another solution is to leave a good margin of say 50px around the
image and set your background to some compatible colour (black seems to
be the most common choice). For an image of width 300 and height 200,
create a window of an extra 100px and add 50px padding to the image:
<script type="text/javascript">
function showPic(t,u,w,h) {
w -= -100;
h -= -100
newWin = window.open('','','height=' + h + ',width=' + w);
var sHTML = [
'<html><head><title>' + t + '</title></head><body',
' style=\'margin: 0; background-color: black;',
' color: black;\'><img src=\'' + u + '\'',
' alt=\'\' border=\'0\' style=\'padding: 50 0 0 50\'>',
'</body></html>'
];
newWin.document.write(sHTML.join(''));
newWin.document.close();
}
</script>
</head><body>
<form action="">
<input type="button" value="Show Picture" onClick="
showPic('A Picture','image1.jpg','300','200');
">
</form>
Incidentally, pop-up blockers will normally allow pop-ups in response
to user actions, but some allow even those to be blocked. Some also
allow exceptions for certain sites.
But in general, pop-ups are bad.
--
Rob