Results 1 to 3 of 3

Thread: Centered PopUp Window

  1. #1
    Join Date
    Jan 2006
    Posts
    234
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question Centered PopUp Window

    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

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    <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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jan 2006
    Posts
    234
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •