Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2002
    Location
    Netherlands
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Picture dimensions centered

    This *.js file creates a centered popup based upon the dimensions (width, height) of the picture that is referred to.
    A click on the picture will close the window (aswell).

    Code:
    <!--
    function show_image(url_img,popup_title,img_alt){
     // pop-up configuration
     var _resizable=0;
     var _status=0;
     var _scrollbars=0;
    
     //load image
     var _img = new Image;
     _img.src=url_img;
    
     // get/calculate required variables
     var _w=_img.width;
     var _h=_img.height;
     var winl = (screen.width - _w) / 2;
     var wint = (screen.height - _h) / 2;
    
     // open window
     var _win=window.open("","","height="+(_h)+", width="+_w+", top ="+wint+", left = "+winl+", resizable="+_resizable+", status="+_status+", scrollbars="+_scrollbars);
    
     // write html content in new window
     _win.document.write("<html>\n <head>\n  <title>\n\t"+popup_title+"\n</title>\n</head>\n");
     _win.document.write("<body style=\"margin:0px;\">\n");
     _win.document.write("<img src=\""+url_img+"\"\n\t alt=\""+img_alt+"\" onClick=\"window.close();\">\n");
     _win.document.write(" </body>\n</html>");
    }
    //-->
    (see the attached Zip file for an example)

    The strange thing is that only the very first time the window is called / 'made' it is NOT centered, but at the bottom right corner and NOT in the specified dimensions. Every next time it works just great, even after deleting the cache. Beats me. My single guess is that perhaps a built in delay will do the trick properly / the first time aswell???

    My problem is, if that's the solution, how / where to built in a time-delay? Any help / suggestions are appreciated.

    Ps IE 5 and 6, XP and windows 95 tested. 2nd question: Is this an IE-thing only?
    Attached Files Attached Files
    Last edited by Membie; 10-20-2003 at 10:09 PM.

  • #2
    New Coder
    Join Date
    Nov 2002
    Location
    Netherlands
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    LOL It seems like I'm having this one solved by adding one single line:
    Code:
     _win.document.write("<meta http-equiv=\"refresh\" content=\"0; URL=url_img\" >\n");
    Don't know / understand why but it works...

    Thanks for 'all' the help and in the hope the script benefits others...

    Greetings, Jan.

  • #3
    New Coder
    Join Date
    Nov 2002
    Location
    Netherlands
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Nope! Got it wrong: not working.

    Sorry. Got a bit overexcited it seems... Problem still excists.

    Would somebody please, please be so kind to help me solve it?

    I noticed a script by 'Beetle' which looked quite simular. I could not get the popups centered in that script either. If possible I prefer solving the problem in this script (if Beetle don't mind, that is. LOL)

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I downloaded your example and it works every time, it never put the popup anywhere except centered like it's supposed to no matter how many times I closed and re-opened the browser.

    (Tested with IE6 SP1 on W2K)
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #5
    New Coder
    Join Date
    Nov 2002
    Location
    Netherlands
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well..., I'm not making it up. Tested it on severall cliŽnts aswell...

    I've noticed, by changing the image (severall times), the problem does not occure on every single one of them.

    Perhaps if you change the image you'll encounter the same problem I'm having? (Remember: only at first / the very first time).

    Thanks btway for responding


  •  

    Posting Permissions

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