Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-20-2003, 06:28 PM   PM User | #1
Membie
New Coder

 
Join Date: Nov 2002
Location: Netherlands
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Membie is an unknown quantity at this point
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
File Type: zip example.zip (17.9 KB, 136 views)

Last edited by Membie; 10-20-2003 at 10:09 PM..
Membie is offline   Reply With Quote
Old 10-20-2003, 11:11 PM   PM User | #2
Membie
New Coder

 
Join Date: Nov 2002
Location: Netherlands
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Membie is an unknown quantity at this point
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.
Membie is offline   Reply With Quote
Old 10-21-2003, 03:32 PM   PM User | #3
Membie
New Coder

 
Join Date: Nov 2002
Location: Netherlands
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Membie is an unknown quantity at this point
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)
Membie is offline   Reply With Quote
Old 10-21-2003, 03:48 PM   PM User | #4
Roy Sinclair
Senior Coder

 
Join Date: Jun 2002
Location: Wichita
Posts: 3,880
Thanks: 0
Thanked 0 Times in 0 Posts
Roy Sinclair will become famous soon enough
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.
Roy Sinclair is offline   Reply With Quote
Old 10-21-2003, 04:01 PM   PM User | #5
Membie
New Coder

 
Join Date: Nov 2002
Location: Netherlands
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Membie is an unknown quantity at this point
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
Membie is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:21 AM.


Advertisement
Log in to turn off these ads.