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!

PopUp: Resize() or Close()? 2

Status
Not open for further replies.

eladi

Programmer
Sep 4, 2001
80
AU
Hi,
I'm new in JavaScript and really tried to figure it out myself. But as you see..:)
a website contains an illustrations with several different objects - to each object, i have an explanatory text to be opened in a popup window.

function fenster_auf(link,win_wid,win_hei) {
var info;
info = window.open(link,'info','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,width='+win_wid+',height='+win_hei+',screenX='+0+',screenY='+0):
}

now, the different texts are not of the same length, so i need to resize the popup-window if the user clicks on an other object to see the information. it tried it with adding

info.resize(win_wid,win_hei);
info.focus();

to the above mentioned script. the size wasn't correct in ie and the script didn't work at all in ns (it has to be compatible). so i thought it would be more simple to close to first close the info-window and then open it with the new parameters. so i put

info.close();

before the opening script. that didn't work at all. so, what's the trick - that works in both browsers!

tnx in advance...adrian
 
try changing resizable=no to resizable=yes
and info.resizeTo(win_wid,win_hei);
 
excellente! works. strange enough in ie the new windows are smaller after resizing than when i just open them...but not big deal, i'll check the browsers and add some 10 pixels in height when it's opened by the ie. tnx a lot!
adrian
 
Hello adrian ,

The reason the info window doesn't resize correctly is that you have a little error in the script.

You can resize a window by using window.resizeTo(x,y) method where x and y are new dimensions in pixels of the window.The other method is resizeBy(x,y),where x and y will be the amount of pixels added to the original window dimensions when it was opened.
The other correction is when you define the window properties.
To give positioning to the window just use this format:


info = window.open(link,','info','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,width='+win_wid+',height='+win_hei+',left=100,top=100');

Using left=integer and top=integer you can display the window a number of pixels from left and from top.
Finally put a link or something into the opened window that will give the visitor the posibility of closing it.

Code in info window:

<a href=&quot;#&quot; onclick=&quot;window.close()&quot;>Close window</a>


I hope this helps,

Kindest Regards

alexfusion
 
I used a similar method to show pictures of my dogs pedigree, but since the picures varies in size I added in a resize after the write and a background color and also a link for closing the window.
It seemed to work nice when I created the page on my computer. However when I placed it on the server the pictures shows up OK the first time, but not if I select a new picture without closing the small window. If I then selected the same picture again it appaeres correct.

Part of the code:
<script language=javascript type=&quot;text/javascript&quot;>
<!--
function ShowMeMore(picURL,picTitle,picText,picWith,picHeight){
newWindow=window.open(picURL,'newWin','resizable=yes,menubar=no');
newWindow.document.write('<body bgcolor=&quot;#555555&quot;><html><title>'+picTitle+'<\/title><head><\/head><body topmargin=&quot;0&quot; leftmargin=&quot;0&quot;><img src=&quot;'+picURL+'&quot;alt=&quot;'+picText+'&quot;><\/body><\/html><center><p><a href=&quot;&quot; onClick=&quot;window.close()&quot;><font color=&quot;#FFFF00&quot;><strong>Click this to close the window.</strong></font></A>');
newWindow.resizeTo(picWith,picHeight);
newWindow.focus();
}
//-->
</script>

<a href=&quot;javascript:ShowMeMore('tiger.jpg','Poulsgaards Be My Talisman - Tiger','Tiger',484,447)&quot;
<font size=&quot;2&quot;>Poulsgaards Be My Talisman</font></a>

If you would like to see it go to:
Any suggestions
Regards Gunnar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top