SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict animgirl's Avatar
    Join Date
    Oct 2003
    Location
    Land of the free, home of the brave
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Tweaking a SitePoint example

    Hey guys and gals,

    Found a script off Sitepoint that does exactly what I want called Resizing a popup to fit an image's size.
    Now, I'm not very familiar with Javascript, but I would like to add something to this script.
    I want it where when someone clicks on another picture link on my site, that the window closes automatically instead of getting minimized. I find that many people won't close each window but will keep opening them and by the time they are done they have several windows minimized they have to close.

    Any help is greatly appreciated and I love this script
    -animgirl
    Elise Henley

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi animgirl,

    Perhaps a better solution would be to load images to the same popup window instead of opening another one. I modified PopupPic() from the article...
    Code:
    var winPopup = null;
    
    function PopupPic(sPicURL)
    { 
      var url = "popup.htm?" + sPicURL;
      if (winPopup && !winPopup.closed) {
        winPopup.location.href = url;
      }  
      else {
        winPopup = window.open(url, "winPopup", "resizable=1,HEIGHT=200,WIDTH=200"); 
      }
    }

  3. #3
    SitePoint Addict animgirl's Avatar
    Join Date
    Oct 2003
    Location
    Land of the free, home of the brave
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds great Mike, but how do I actually implement that?
    I've experimented and I'm not sure where exactly to intertwine that in the JS code.

    animgirl
    Elise Henley

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Without seeing your page I can't tell you exactly where to insert it into your page.

    Add this line:
    Code:
    var winPopup = null;
    Replace the existing PopupPic function with this one:
    Code:
    function PopupPic(sPicURL)
    { 
      var url = "popup.htm?" + sPicURL;
      if (winPopup && !winPopup.closed) {
        winPopup.location.href = url;
      }  
      else {
        winPopup = window.open(url, "winPopup", "resizable=1,HEIGHT=200,WIDTH=200"); 
      }
    }

  5. #5
    SitePoint Addict animgirl's Avatar
    Join Date
    Oct 2003
    Location
    Land of the free, home of the brave
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
    <head>
     <title>Alliance Pictures</title>
     <link rel="stylesheet" href="/styles/alliance.css" type="text/css" />
     <script language='javascript'>
       var winPopup = null;
       var arrTemp=self.location.href.split("?");
       var picUrl = (arrTemp.length>0)?arrTemp[1]:"";
       var NS = (navigator.appName=="Netscape")?true:false;
    
         function FitPic() {
           iWidth = (NS)?window.innerWidth:document.body.clientWidth;
           iHeight = (NS)?window.innerHeight:document.body.clientHeight;
           iWidth = document.images[0].width - iWidth;
           iHeight = document.images[0].height - iHeight;
           window.resizeBy(iWidth, iHeight);
           self.focus();
         };
         
         function close_window()
      {
      document.close(); // closes popup
      }
     </script>
     
    
    </head>
    <body onload='FitPic();' topmargin="0"  
    marginheight="0" leftmargin="0" marginwidth="0">
     <script language='javascript'>
     document.write( "<img src='" + picUrl + "' border=0>" );
     </script>
    </body>
    </html>
    I inserted the variable at the top because I know that's gotta be right, but when I replace the whole function section with the code suggested, it doesn't work correctly. The pics come up but the window doesn't resize and they come up in separate windows.

    What am I doing wrong? heh
    animgirl
    Elise Henley


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
  •