Results 1 to 7 of 7

Thread: Close window JavaScript

  1. #1
    Join Date
    Mar 2010
    Posts
    197

    Close window JavaScript

    Hello,
    I want to close a window using a java script, I have a piece of code but that is not working. So, if you know how to do this or if you can give me some idea to do this then it will be appreciated. Thank you for your help.

  2. #2
    Join Date
    Nov 2009
    Posts
    356

    Re: Close window JavaScript

    Hello,
    This is the code you are looking for
    Code:
    <html>
    <head>
     <title>Window close </title>
    </head>
    <SCRIPT language="JavaScript1.2">
    function popuponclick()
    {
     testwindow = window.open("",
        "mywindow","status=1,width=350,height=150");
    testwindow.document.write('<H1>The Popup Window</H1>');  
    }
    
    function clpop()
    {
     if(false == testwindow.closed)
     {
        testwindow.close ();
     }
     else
     {
        alert('Window already closed!');
     }
    }
    </SCRIPT>
    <body>
    <P>
    <A href="javascript: popuponclick()">Open Popup Window</A>
    </P>
    <P>
    <A href="javascript: clpop()">Close the Popup Window</A>
    </P>
    </body>
    </html>

  3. #3
    Join Date
    Nov 2009
    Posts
    359

    Re: Close window JavaScript

    Hello,
    The above is correct alternatively you can also try the following
    Code:
    <html>
    <head>
    <title>Test close window</title>
    <script language="JavaScript">
    <!--
    
    function opwn(){
    window.open('example.html', '');
    window.close();
    }
    
    // -->
    </script>
    </head>
    
    <body onload="window.opener='';opwn()">
    </body>
    </html>

  4. #4
    Join Date
    Nov 2009
    Posts
    446

    Re: Close window JavaScript

    Hello,
    Even this can help
    Code:
    <SCRIPT language="JavaScript">
    <!--
    var brwnm=navigator.appName;
    if (brwnm=="Netscape") {
    
    function clwinnm()
    {
    window.open('','_parent','');
    window.close();}
    }
    else {
    if (brwnm=="Microsoft Internet Explorer")
    {
    function clwinnm()
    {
    window.opener = "whocares";
    window.close();
    }
    }
    }

  5. #5
    Join Date
    Nov 2009
    Posts
    343

    Re: Close window JavaScript

    Hey,
    Take a look at the following code
    Code:
    <script>
    function handunld()
    {
    event.returnValue = "Click cancel to return to the blah";
    }
    </script>
    
    <body onbeforeUnload="handunld()">

  6. #6
    Join Date
    Nov 2009
    Posts
    446

    Re: Close window JavaScript

    Hello,
    Take a look at the following code
    Code:
    function clallwind()
    {
    for(var x=0;x<children.length;x++)
    {children[x].close();
    }
    //Oh, and close self!
    window.close();
    }

  7. #7
    Join Date
    Nov 2009
    Posts
    347

    Re: Close window JavaScript

    Hello,
    This code can help you
    Code:
    <script type="text/javascript"> 
    function nwwind() { 
     var dy = new Date(); 
     var id=dy.getTime(); 
     var args = 'width=400,height=400,scrollbars,resizable'; 
     var message='<p><a href="#" onClick="setTimeout(\'window.close()\',500);return false;">'+ 
       'This window will self-destruct half a second after you click this link</a></p>'+ 
     '<form><input type="button" onClick="setTimeout(\'window.close()\',500);"'+ 
     ' value="Or click this button"></form>'; 
     var win=open('',id,args); 
     win.document.write(message); 
     win.document.close(); 
    return false; 
    } 
    </script>

Similar Threads

  1. cannot close Logitech Webcam Help window
    By Adisa in forum Windows Software
    Replies: 2
    Last Post: 30-12-2011, 04:48 AM
  2. Unable to close QuickTime 10 window
    By Lyudmyla in forum Windows Software
    Replies: 6
    Last Post: 19-04-2011, 10:13 AM
  3. Problem with close window in PHP
    By Duck in forum Software Development
    Replies: 3
    Last Post: 08-04-2009, 08:57 AM
  4. Need to close All Window
    By Aakarshan.d in forum Operating Systems
    Replies: 4
    Last Post: 12-02-2009, 08:58 AM
  5. HTML code to close window
    By Jacek in forum Software Development
    Replies: 5
    Last Post: 12-01-2009, 11:55 PM

Tags for this Thread

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
  •  
Page generated in 1,717,351,912.12855 seconds with 16 queries