Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Close all pages of a website if the main page is closed

  1. #1
    Join Date
    Dec 2009
    Location
    NY NY USA
    Posts
    230
    Thanks
    158
    Thanked 1 Time in 1 Post

    Default Close all pages of a website if the main page is closed

    Hi:

    On this website test page, if the "Contact Renee" button is clicked the contact page opens. In the event that page is not used (a message not sent),
    when the visitor brows to a different website or closes the browser, the contact page stays open. Is there javascript that can close all pages of a
    website if the visitor brows away from that website? That is, I'd like the "Contact Renee" page to close if the visitor leaves the website and doesn't
    send a message.

    I thought this might work, but it doesn't:
    Code:
    <script type="text/javascript">        
    // open new window:
    var windows = [];
    windows.push(window.open('http://www.reneesrosegarden.com', '_blank'));
    
    // close them all:
    for(var i = 0; i < windows.length; i++){
        windows[i].close()
    }         
    </script>
    Thanks
    Last edited by KennyP; 02-25-2016 at 07:14 AM.

  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

    Well, hmm. It might if that was how the window was opened. I don't think there's a way to guarantee what I think you're talking about. However, there is a way, in most cases, to close the contact window via the reference to it that was created when it was opened if the window that opened it is closed. So, for example on http://www.reneesrosegarden.com/ where it has:

    Code:
    <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,resizable=no';
    win=window.open(mypage,myname,settings);}
    // -->
    </script>
    That's the actual code currently used to open the contact window and win is the reference it creates. So one can use win as a reference to close it if that page closes. And since jQuery is already in use, we can do that fairly unobtrusively (addition highlighted):

    Code:
    <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,resizable=no';
    win=window.open(mypage,myname,settings);}
    $(window).unload(function(){if(win){win.close();}});
    // -->
    </script>
    - John
    ________________________

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

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    KennyP (02-24-2016)

  4. #3
    Join Date
    Dec 2009
    Location
    NY NY USA
    Posts
    230
    Thanks
    158
    Thanked 1 Time in 1 Post

    Default

    Thank you for your reply John. I tried your posted code-addition but unfortunately the Contact page doesn't close even if the website page that opened it is closed - but it should.
    You can see the effect of the additional-code on the Contact page that no longer resizes nor closes here on this test page.

    Also, it makes the browser re-open the initial home page as a pop-up.
    Last edited by KennyP; 02-25-2016 at 02:06 AM.

  5. #4
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default

    Couldn't you make a cookie so see if the main page is still up. Once you close the main page use the unload function to remove the cookie. Once they try to move the mouse it checks the cookie if it is null then close or redirect the page?
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  6. The Following User Says Thank You to Deadweight For This Useful Post:

    KennyP (02-25-2016)

  7. #5
    Join Date
    Dec 2009
    Location
    NY NY USA
    Posts
    230
    Thanks
    158
    Thanked 1 Time in 1 Post

    Default

    Thanks for your reply Deadweight. How would you write that out?

  8. #6
    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

    You have not made the suggested change I proposed.
    - John
    ________________________

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

  9. The Following User Says Thank You to jscheuer1 For This Useful Post:

    KennyP (02-25-2016)

  10. #7
    Join Date
    Dec 2009
    Location
    NY NY USA
    Posts
    230
    Thanks
    158
    Thanked 1 Time in 1 Post

    Default

    Code:
    <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,resizable=no';
    win=window.open(mypage,myname,settings);}
    $(window).unload(function(){if(win){win.close();}});
    // -->
    </script>
    I inserted the above code above into the main test page, but that is all I understood you suggest I do. Did you propose I do something else I didn't understand?
    Last edited by KennyP; 02-25-2016 at 07:16 AM.

  11. #8
    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

    First I've seen that page. Unlike the page where I suggested you place that, this test page has invalid coding which renders that entire block of code inoperable:

    Code:
    <script language="javascript" type="text/javascript">
    <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,resizable=no';
    win=window.open(mypage,myname,settings);}
    $(window).unload(function(){if(win){win.close();}});
    // -->
    </script>
    There could also be other problems, but that extra opening script tag must be removed before any of the code there will be used.
    - John
    ________________________

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

  12. The Following User Says Thank You to jscheuer1 For This Useful Post:

    KennyP (02-25-2016)

  13. #9
    Join Date
    Dec 2009
    Location
    NY NY USA
    Posts
    230
    Thanks
    158
    Thanked 1 Time in 1 Post

    Default

    Thank you very much John. Your code works perfectly.

    With your code, when the main index page is closed or if the user browses to another site, the Contact page closes automatically,

    whether a message is sent or not, just as I wanted.

    Previously in an effort to make everything clearer, I placed an extra opening tag that made it all worse instead. Sorry about that.

    Thanks again,

    Kenny
    Last edited by KennyP; 02-25-2016 at 10:26 PM.

  14. #10
    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

    Great! And you're doing the right thing there. You can almost never have too many backups. It's wise to try out new code on a test page. Sadly, sometimes typos creep in that way, which is what I think may have happened here. Worked out in the end. That's what matters.
    - John
    ________________________

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

  15. The Following User Says Thank You to jscheuer1 For This Useful Post:

    KennyP (02-26-2016)

Similar Threads

  1. Animated Collapsible DIV v2.4 shrink when close and go to main page
    By Dahls in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 05-24-2013, 10:44 AM
  2. Smart Folding Tree Menu - Close one main folder when a new one is opened.
    By sallydeleeuw in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 10-01-2008, 11:20 AM
  3. Want to close a popup and open the link in main window
    By egdcltd in forum Looking for such a script or service
    Replies: 0
    Last Post: 04-04-2008, 05:50 PM
  4. multiple line main headings overlap when closed
    By leh12345678 in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 03-28-2007, 01:42 PM
  5. Replies: 3
    Last Post: 10-06-2005, 05:39 AM

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
  •