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

Thread: close window automatically

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

    Default close window automatically

    In my design, i want my Internet Explorer close automatically. Here is my code:

    Code:
    <script LANGUAGE="JavaScript">
    function closePg(){
    	window.close();
    	return true;
    }
    </script>
    <body onLoad="return closePg()"></body>
    However, a pop up message was displayed after that. If nobody click the OK button, then the page will not close itself.
    Attachment 445

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yup. That will happen.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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

    Default

    Quote Originally Posted by Twey
    Yup. That will happen.
    anyway to avoid that message box from pop up?

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

    Only works in some browsers but, IE (the one that generated your confirm dialogue box) is one of them:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function closeIt(){
    window.opener=self;
    window.close();
    }
    </script>
    </head>
    <body onload="closeIt();">
    
    </body>
    </html>
    - John
    ________________________

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

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

    Default

    Yeah, this is the thing i want!
    thank you guys.

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

    Default

    Yes, but is it?? -*Insert maniacle laughter here

    This is my personal favorite way to do this.

    Code:
    <script language="javascript">
    onload=function closeIt(){
    var cl=window.confirm("Close the window?")
    if (cl) {window.opener=self;window.close()}
    else {return closeIt()}
    }
    </script>
    This does tend to tick off users

    edit: don't use this, jscheuer1 is going to try to ban me for it!
    Last edited by mburt; 08-01-2006 at 05:05 PM.
    - Mike

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Isn't that rather what the OP was hoping to avoid in the first place? :-\
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yea I think so too.

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

    Default

    But, it forces you to close the window. When you hit "cancel" it returns the function.
    - Mike

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Argh! I just read that. That's *awful.*

    Recursion is not a good idea, especially when you don't control the level to which it will recurse Every time the user clicks "Cancel," the function is run again, but the original call will still be in memory, since it won't return until the child does. That means that by the time they've clicked "Cancel" twenty times, you've got twenty-one copies of the function running, all at once.

    Of course, if the user panics and just holds down enter, you could end up with 200+ copies of this function running -- a sure way to bring a monolithic system to its knees.

    Whatever you do, do not use that code.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •