By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,830 Members | 1,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,830 IT Pros & Developers. It's quick & easy.

need help opening a window

P: n/a
MM
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.

The code works, however there is a white border on the top and left
side of the image. If I add 20 to the width and height of the window
then there is a white border around the whole image.

Is there anyway to have the window the exact size of the image,
without this white border? I know there is probably a simple solution,
but I'm a beginner at JavaScript.

Any help is much appreciated.
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"MM" <ca***********@yahoo.ca> wrote in message
news:jv********************************@4ax.com...
I am using the following code to display an image in a seperate
window.


do you really need a new window? I think "thumbnail>big image in new
window" is a pita. also, pop up blockers will block you.

sorry to not answer your ?.
Jul 23 '05 #2

P: n/a
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
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.