Forum Moderators: open

Message Too Old, No Replies

White space around images in popup windows

How do I get rid of it?

         

Lindsey Kuper

7:28 pm on Jun 15, 2004 (gmt 0)

10+ Year Member



Hi. I'm using a JavaScript function that comes with Dreamweaver so what when users click on thumbnail images, a larger window pops up with the image. Here's the function:

function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
return false;
}

Here's an example of how I'm using it in the code:

<a href="wrigleysign.jpg" onclick="MM_openBrWindow('wrigleysign.jpg','','width=360,height=249');return false"><img src="wrigleysign.jpg" width="360" height="249" border="0"></a>

This works great, except for one thing: the image doesn't appear in the very top left-hand corner of the pop-up window -- there's some white space around it, and the right and bottom edges of the image are cut off, because they don't fit in the pop-up window. I'm wondering, is there some way around this problem, that's less messy than changing the width and height that I'm passing to the function every time?

Thanks in advance.

DrDoc

7:38 pm on Jun 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have two options:

1) have the image load within a page (where the HTML removes the default padding)
2) resize the pop-up window to account for the padding (which varies between browsers)

createErrorMsg

8:20 pm on Jun 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this script:

function imgWin(url,width,height) {
features= "width=" + width + ",height=" + height;
newWin = window.open ('', '', features);
pageCode = "<html><head><style type='text/css'>body {margin:0; padding:0; border:0;}</style></head>";
pageCode += "<body><img src='" + url + "'></body></html>";
newWin.document.write(pageCode);
newWin.document.close();
}

Reference it like this in the html:
<a href="image.jpg" onclick="imgWin(this.href,'640','480'); return false;">Click!</a>

As per Doc's first suggestion, this will open the new window to your image size, then write html code into it for displaying the image. The html is styled to get rid of the margins and padding, putting the image up in the top-left corner of the page.

Hope it helps.

Lindsey Kuper

11:45 pm on Jun 16, 2004 (gmt 0)

10+ Year Member



createErrorMsg, that script is precisely what I needed. Thank you so much! =)