SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot arthaus's Avatar
    Join Date
    Jun 2002
    Location
    Pasadena, CA
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Auto-Size Image Popups

    Hi all,

    I have the following center popup window code...
    Code:
    function popPhoto(imagesrc,imgwidth,imgheight) {
    	
    	if (isMinNS4) {
    		// Mozilla and Netscape window size fix
    		winwidth = imgwidth + 4;
    		winheight = imgheight + 4;
    	} else {
    		winwidth = imgwidth;
    		winheight = imgheight;
    	}
    	
    	var sX = (screen.width - winwidth) / 2;
        var sY = (screen.height - winheight) / 2 - 30;
    	var wstring = "width=" + winwidth;
    	var hstring = "height=" + winheight;
    	
    	var winParams = wstring + "," + hstring + ",left=" + sX  + ",top=" + sY  + ",toolbar=0,resizable=0,scrollbars=0,location=0,status=0"
    	
    	popwin=window.open("","",winParams);
    	popwin.document.open();
    	popwin.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\r\t\t"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">\r<html lang="en">\r<head>\r\t<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">\r\t<title>photo_detail<\/title>\r<\/head>\r\r<body leftmargin="0" rightmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#666">\r\t<div style="text-align:center;"><a href="javascript:self.close();" title="click anywhere to close"><img src="'+imagesrc+'" width="'+imgwidth+'" height="'+imgheight+'" border="0"><\/a><\/div>\r<\/body>\r<\/html>');
    	popwin.document.close();
    }
    Q: How can I convert it to dynamic window size depending called image?

    Thankx in advance,
    Arthur

  2. #2
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a Javascript issue really...

    First, use the DOM to get the size of an IMG and then based on the width and height, calculate the co-ords first based on the screen width and height, and lastly once you've positioned the window, resize the window to the width and height of the IMG (which you should have already);

    Can someone move this to the Javascript forum please ?

  3. #3
    SitePoint Zealot jadmadi's Avatar
    Join Date
    Sep 2003
    Location
    Jordan
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, This is PHP Issue
    play with PHP GetImageSize
    http://www.php.net/manual/en/function.getimagesize.php

  4. #4
    SitePoint Evangelist Daijoubu's Avatar
    Join Date
    Oct 2002
    Location
    Canada QC
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have it like:
    HTML Code:
    	function resize() {
    		if (document.images[0]) window.resizeTo(document.images[0].width +12, document.images[0].height+32);
    	}
    Merge it with your popup center thingy
    Speed & scalability in mind...
    If you find my reply helpful, fell free to give me a point

  5. #5
    SitePoint Zealot arthaus's Avatar
    Join Date
    Jun 2002
    Location
    Pasadena, CA
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Daijoubu
    I have it like:
    HTML Code:
    	function resize() {
    		if (document.images[0]) window.resizeTo(document.images[0].width +12, document.images[0].height+32);
    	}
    Merge it with your popup center thingy
    Hi Daijoubu,

    Currently I use my original function as...
    Code:
    <a href="img/usflag.jpg" onclick="popPhoto(this.href,640,480);this.blur();return false;" title="Zoom in on this photo">open</a>
    Q: How would I merge/consolidate with your code?

    Regards,
    Arthur

  6. #6
    SitePoint Evangelist Daijoubu's Avatar
    Join Date
    Oct 2002
    Location
    Canada QC
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look at my site, the right colum screenshot use it
    Pop up window's resized automaticly (the +12/+32 is for IE, let me know if you found a better way )
    Speed & scalability in mind...
    If you find my reply helpful, fell free to give me a point

  7. #7
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is the +12 and +32 due to the scrollbars ? I know that IE [only this browser; not Opera] has an issue with the scrollbars though at the moment I cannot exactly remember the fix.

    Though there is an object exposed to Javascript for the scrollbars which is used to rework your calculations yes ? Maybe have a look over at www.webreference.com/js to see if you can find the ''tip'' ?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •