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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Window 1

Status
Not open for further replies.

GP

IS-IT--Management
Jan 14, 2002
61
GB
Hello

I use the following code to open a pop-up window and load an image. I send the image size details so that the pop-up window is the right dimensions.

My problem is that if you dont close the window when you click another pop-up it does not change the dimensions, so the image does not fit.

How do I either 1) force it to change the size or 2) close the open window and open a new one.

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
//Script to open a new HTML page in a window showing a close up of picture.
function openImage(imagepath,imagename,windowname,width,height,features)
{
width=(width)?width:screen.width/2;
height=(height)?height:screen.height/2;
var screenX = (screen.width/2 - width/2);
var screenY = (screen.height/2 - height/2);
var features= &quot;width=&quot; + width + &quot;,height=&quot; + height +&quot;,scrollbars=no,status=no&quot;;
features += &quot;,screenX=&quot; + screenX + &quot;,left=&quot; + screenX;
features += &quot;,screenY=&quot; + screenY + &quot;,top=&quot; + screenY;

OpenWindow=window.open(&quot;&quot;, windowname, features);
OpenWindow.document.write(&quot;<TITLE>&quot; + imagename + &quot;</TITLE>&quot;)
OpenWindow.document.write(&quot;<BODY BGCOLOR=#000000 onload='self.focus();'>&quot;)
OpenWindow.document.write(&quot;<h3><font color=\&quot;white\&quot;>&quot; + imagename + &quot;</font></h3>&quot;)
OpenWindow.document.write(&quot;<P><font color=\&quot;white\&quot;>This is a close up of the image you requested.</font></P>&quot;)
//OpenWindow.document.write(&quot;<img src='&quot; + imagepath + &quot;' width = 200>&quot;)
OpenWindow.document.write(&quot;<P><img src='&quot; + imagepath + &quot;'></P>&quot;)
OpenWindow.document.write(&quot;</BODY>&quot;)
OpenWindow.document.write(&quot;</HTML>&quot;)
OpenWindow.document.close()
self.name=&quot;main&quot;
}
</SCRIPT>
 

GP,

This might work...

Add a variable in your Javascript, but outside the openImage function:

Code:
var OpenWindow = null;

And then modify your &quot;
Code:
window.Open
&quot; line from:

Code:
OpenWindow=window.open(&quot;&quot;, windowname, features);

To:

Code:
if (OpenWindow!=null) OpenWindow.close(); OpenWindow=window.open(&quot;&quot;, windowname, features);

I haven't tested that, but in theory it should work.

Hope this helps,

Dan
 

Basically, all the code doing is keeping track of whether or not you already have a window open. If you do, it closes it before re-opening a new one.

Dan
 
Thanks, it works perfectly....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top