Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-05-2010
Member
 
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.
Reply With Quote
  #2  
Old 10-05-2010
Member
 
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>
Reply With Quote
  #3  
Old 10-05-2010
Member
 
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>
Reply With Quote
  #4  
Old 10-05-2010
Member
 
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();
}
}
}
Reply With Quote
  #5  
Old 10-05-2010
Member
 
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()">
Reply With Quote
  #6  
Old 12-05-2010
Member
 
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();
}
Reply With Quote
  #7  
Old 13-05-2010
Member
 
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>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 06:20 AM.