Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Jan 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to close a window

    I would like to close the window itself after I click some button or Hyperllink on it, or even press some key.
    Any answer would be appreated.
    Thank you!

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <a href="#" onclick="window.close();">Close this Browser Window"</a>
    Of course the user will get a confirmation request from the browser asking if they really want to close the window unless this window is one you opened.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    Regular Coder
    Join Date
    May 2003
    Location
    34░ 54' N 82░ 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have seen some 'close this window' that doesn't give a 'Close Window?' confirmation button. How is that done?
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Script generated windows (ie popups) can be closed at any time - from within, or from the generating page. There is a bug in iew that allows you to set the opener propertyr and then close the window without asking, but that is a foul hack.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Not only IE but majority of the browsers have that bug.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Well, currently only saf and moz seems to disallow it. Still, one may hope. I've reported this bug to Opera as well, hoping they will correct it before 7.50 final is released.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    According to the site that exploits this bug, this is the list of the browsers that either do or don't work with that hack.
    Attached Thumbnails Attached Thumbnails How to close a window-list.jpg  
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #8
    New Coder
    Join Date
    Jan 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for the replies.
    Another question is, how to close it automaticly after a given time(e.g. 3 seconds) without doing anything.

  • #9
    New Coder
    Join Date
    Jan 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And another possibility is to press one key to close it:
    But I don't how to do it by press e.g. "Enter",
    is that right to say: <a href="#" onclick="window.close();" accesskey="Chr13">.
    And if I would like to press any key to close the window?

  • #10
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Aaack! It seems Opera actually allows closing of any window, not just using this hack. This definitely goes to the OBTS.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #11
    New Coder
    Join Date
    Jul 2003
    Location
    London
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you want to close a window without the browser asking for a confirmation, use the following code:

    Paste the following function into the head of your document :

    function closeWinNoDialog() {
    window.opener = top;
    window.close();
    }


    Then call the function using:

    <a href="javascript:closeWinNoDialog();">close window</a>

    Hope this helps.....

  • #12
    New Coder
    Join Date
    Jul 2003
    Location
    Houston, Texas
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is one I use. Seems if you give the window a name, you become the owner and then you canl close it without getting the confirm window. I use this in lots of my applications. Hope this helps.

    <?php

    $sript_err=str_repeat("&middot",7)." Scripting Error ".str_repeat("&middot",7);

    ?>
    <noscript>
    <html>
    <head><title>Index</title></head>
    <body background="blue_fade.jpg"><br><br><br><br><br><br>
    <center><font size="8" face="arial" color="red">
    <b><?php echo $script_err; ?></font><br><br><br>
    <center><font size="6" face="arial" color="cyan">
    <b>Your web browser does not have scripting enabled.<br>
    Scripting must be enabled in order to run this application.<br><br>
    Contact ITCS to have scripting enabled on your workstation
    </font>
    <bgsound src="notify.wav"></bgsound>

    </body>
    </html>
    </noscript>

    <html>
    <head><title>Index</title>

    <script language="javascript">
    function openSite(){
    var wide=screen.width;
    var high=screen.height;
    var where_to;

    switch(wide)
    {
    case 640:
    switch(high)
    {
    case 480:
    where_to='ps_page_one_640.php';
    }
    break;
    case 800:
    switch(high)
    {
    case 600:
    where_to='ps_page_one_800.php';
    }
    break;
    case 1024:
    switch(high)
    {
    case 768:
    where_to='ps_page_one_1024.php';
    }
    break;
    case 1152:
    switch(high)
    {
    case 864:
    where_to='ps_page_one_1152.php';
    }
    break;
    case 1280:
    switch(high)
    {
    case 1024:
    where_to='ps_page_one_1280.php';
    }
    break;
    default:
    where_to='ps_page_one_1024.php';
    }

    var mainwin = window.open(where_to,"mainwin", "");
    window.opener='England_swings';
    window.close();
    }
    </script>

    </head>

    <body onload="openSite()">

    </body>
    </html>
    Beyond a critical point within a finite space, freedom diminishes as numbers increase. ...The human question is not how many can possibly survive within the system, but what kind of existence is possible for those who do survive."


  •  

    Posting Permissions

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