Log in

View Full Version : Centered PopUp Window



Cheng
06-24-2006, 01:18 PM
Can someone please tell me what to change so that the popup window closes autmatically when someone clicks somewhere outside the popup window.

Here the script I'm using:


<--Begin
function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
// End -->

Thanks a lot.
Cheng

jscheuer1
06-25-2006, 05:30 AM
If you are opening an actual page in that pop up (as opposed to just an image for example) the code to close it would go on the launched page, something like:


<script type="text/javascript">
if (self.opener)
window.onblur=function(){self.close();}
</script>


If you are not launching a page, then, you need to. You can dynamically create a page to launch and have the above script written to it but, I'm getting ahead of myself here.

Cheng
06-25-2006, 06:48 AM
Hi John.

Thanks for your reply.
I just found a script that you gave me before and now I'm using this one:


<script language="javascript" type="text/javascript">
<!--

var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,re sizable=no';
win=window.open('',myname,settings);
win.document.write('<body style="margin:0;padding:0;" onblur="self.close()"><img src="'+mypage+'">');
win.document.close();
}
// -->
</script>

It's working fine.
Thanks again.
Cheng