Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: popup window close any where on window onclick

  1. #1
    Join Date
    Jul 2006
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default popup window close any where on window onclick

    1) Script Title: Popup Window Generator "Wizard" Eric

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/popwin.htm

    3) Describe problem:


    Need assistance in making Eric's popup window close.

    Popup window is open by clicking on an image. I want to close the image by clicking anywhere on the popup window verse the "X" button.

    Is there a way to insert a function for onclick win.close().

    Thanks.



    Edit/Delete Message

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Code:
    <input type="button" value="[X]" style="float:right" onclick="window.close()">
    - Mike

  3. #3
    Join Date
    Jul 2006
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hello Mike,

    Here's the code to the .html:

    <p><a href="r50v2_images/r50v2_collective_servo.jpg" onclick="NewWindow(this.href,'mywin','520','680','yes','center');return false" onfocus="this.blur()"> <img src="r50v2_images/r50v2_collective_servo_sml.jpg" alt="Collective Servo Rotated" width="200" height="267" border="0" class="img-R" /></a>



    This opens a new window in which I want to click "ANYWHERE" on the new window.

    I am not sure where to put this script at in the above code?

    <input type="button" value="[X]" style="float:right" onclick="window.close()">

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Oh, I thought you wanted it to be executed from a button.

    This is a script that from any point on the page it will close the window.

    Code:
    <script>
    document.onclick=function() {window.close()}
    </script>
    - Mike

  5. #5
    Join Date
    Jul 2006
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hello Mike,

    Here's Eric's JS script and its call up externally:

    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,resizable=yes';
    win=window.open(mypage,myname,settings);}



    Since it is a picture (jpg file) that is requested there are NO .html page to insert the below script to. So I am not sure where to insert this script to.

    <script>
    document.onclick=function() {window.close()}
    </script>



    Forgive me but I am self teaching myself and all of this html, css and JS is abit foreign.

    I do appreciate any help and advice.... Thanks.

  6. #6
    Join Date
    Jul 2006
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok the later script that mike gave works with DW8's behavoir.


    Hopefully I can find a solution but if all else fail I'll have to go back to all the pages and change all the href scripst.

    Thanks again for all the advice.


    updated:
    It still doesn't solve my problem since I can't put the script on the new window since it is not a .html page ....
    Last edited by Girard Ibanez; 07-31-2006 at 02:36 AM.

  7. #7
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Code:
    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,resizable=yes';
    win=window.open(mypage,myname,settings);}
    
    document.onclick=function() {window.close()}
    - Mike

  8. #8
    Join Date
    Jul 2006
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Mike,


    I appreciate all your efforts but they all work if the popup window called out is a .html.

    But for a image window .... I still have to use the "X" button to close.


    I installed the code you gave and called it out using an external file but the pop up window does not close when clicked on any part of the popup window.

    Not sure what I'm doing wrong....two days and still no luck ...

  9. #9
    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

    Something like this will work, probably need some fine tuning:

    Code:
    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,resizable=yes';
    win=window.open('',myname,settings);
    win.document.write('<script type="text/javascript">onclick=function(){self.close();};<\/script>');
    win.document.write('<body bgcolor="#dddddd"  text="#000000" style="margin:10px;padding:0;overflow:hidden;">');
    win.document.write('<img width="'+(w-20)+'" height="'+(h-20)+'" galleryimg="no" src="'+mypage+'">');
    win.document.close();
    }
    - John
    ________________________

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

  10. #10
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Oh. I thought Girard Ibanez was using a pop-up from a source (URL).
    - Mike

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
  •