Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting newwindow to open at images dimensions

Status
Not open for further replies.

DeepBlerg

Technical User
Jan 13, 2001
224
0
0
AU
Hi,

I have the following javascript in the <head>:

<SCRIPT LANGUAGE=&quot;JavaScript&quot; TYPE=&quot;text/javascript&quot;> var javascript_version = 1.0;</SCRIPT>
<SCRIPT LANGUAGE=&quot;JavaScript1.1&quot; TYPE=&quot;text/javascript&quot;> javascript_version = 1.1;</SCRIPT>
<SCRIPT LANGUAGE=&quot;JavaScript&quot; TYPE=&quot;text/javascript&quot;>
<!--
var newwin;

function launchwin(winurl,winname,winfeatures)
{
newwin = window.open(winurl,winname,winfeatures);
if(javascript_version > 1.0)
{
setTimeout('newwin.focus();',250);
}
}
//-->
</SCRIPT>



and this is the link I use in the body:

<a href=&quot;javascript:launchwin('./images/pics/filename.jpg','newwindow','left=22,top=22,scrollbars=yes')\&quot;>file</a>

since there's heaps of images that get loaded through PHP how can I set the newwindow to open to the image dimensions instead of having to specify them with height and width because all the image dimensions are different.

Thanks.
 
here is what i use on my so called &quot;gallery&quot;:

1. open a window of pre-defined size (some sort of 300x200)

2. write the code into that window that acts on that popup's load, there i catch the image's width/height & resize the window due to them..

here is a script:
Code:
function MakeItQuick(param3){//param1,param2,
params=&quot;addressbar=no,resizable=yes&quot;;
//used to define default sizes only for netscrap:
//see - it doesn't resizes in netscrap.. :(
//if (document.layers){
params+=&quot;,width=410,height=300&quot;;
//}
bbb = open(&quot;&quot;,&quot;&quot;,params);
bbb.document.open();
//img's sizes:
// width=&quot;+param1+&quot; height=&quot;+param2+&quot;
content=&quot;<html>\n&quot;+
&quot;<head>\n&quot;+
&quot;<scr&quot;+&quot;ipt language='jav&quot;+&quot;ascr&quot;+&quot;ipt'>\n&quot;+
&quot;<!--\n&quot;+
&quot;function init(){\n&quot;+
&quot;d=self.document;\n&quot;+
&quot;imag = (d.images['car'] || d.getElementById('car'));\n&quot;+
//&quot;alert('obj: '+imag+'\\nwidth: '+imag.width+'\\nheight: '+imag.height);\n&quot;+
&quot;w=imag.width+15;h=imag.height+35;\n&quot;+
&quot;top.resizeTo(w,h)\n&quot;+
&quot;}\n&quot;+
&quot;//-->\n&quot;+
&quot;</scr&quot;+&quot;ipt>\n&quot;+
&quot;</head>\n&quot;+

&quot;<body marginheight='0' marginwidth='0' leftmargin='2' topmargin='2' onload='init()'>\n&quot;+
&quot;<img src='&quot;+param3+&quot;' border=0 name='car' id='car'>\n&quot;+
&quot;</body>\n&quot;+
&quot;</html>&quot;;
bbb.document.write(content);
bbb.document.close();
}

i called this script &quot;magic.js&quot; & included into page:
Code:
<script language=&quot;JavaScript&quot; src=&quot;magic.js&quot;></script>

and here is how i call it:

<a href=&quot;javascript:void(MakeItQuick('gallery/carnival/1_b.jpg'));&quot;><img src=&quot;gallery/carnival/1_m.jpg&quot; width=&quot;68&quot; height=&quot;40&quot; border=&quot;0&quot; alt=&quot;kia carnival ýêñòåðüåð&quot;></a>

hope you understood the stuff..
 
tuz. Please read my FAQ on coding convention. It will enhance your code without you making great efforts. Your logic seems good but it would make reading your code easier for other people if you :

1. used better names for you variables (magic.js could be resizeImages.js)
2. aligned things to make it more readable.
3. removed useless &quot; in attributes.

I believe that netscape has a real problem dealing with script you write with javascript.

Example :

document.write(&quot;<script>&quot;
+&quot;alert('how do you do?')&quot;
+&quot;</script>&quot;);

could this be one of your problems?

A trick I used on a page a while back to get the actual image size was to have a div at -500 left and -3000 top and have it load. then I would farm out the clip.right and clip.top or height and width values of that image inside the div.

You could do something similar to resize your window according to the image height and width.

Of course I don't support NS4 anymore (for 6 months now). And I do remember problems with certain version of NS4.

read to see why I gave up support for NS4

Hope this helps. Gary &quot; Haran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top