script to close self browser window

I am wanting to add a function that automatically closes the browser window when a button is clicked.
Any and all help will be greatly appreciated thanks.

FB
frankybonesAsked:
Who is Participating?
 
YZlatConnect With a Mentor Commented:
call this function the following way:

closeCurrentWin( true)
0
 
Ryan ChongCommented:
try use window.close() ?

example:

<input type="button" name="Button" value="Close" onclick="window.close()">
0
 
FataquiCommented:
Hi


one way.................

button on your main page...............
<center>
 <form>
  <input type='button' onclick="parent.location='/close.php?close=1';" value='Close Me'>
 </form>
</center>


script the button calls..................

<?

if ( ! empty ( $_GET['close']) )
{
      call_close ();

}



function call_close ()
{

echo "<script type='text/javascript' language='JavaScript 1.2'>

      if ( parent.window )
      {
            window.opener=self;
      }

      window.close ();

</script>
";

}


?>

example...................

http://zip.ya-right.net/test.html



Fataqui!
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
YZlatCommented:
use self.close();


function closeCurrentWin( closeSelf){
      if(closeSelf) self.close();
}
0
 
YZlatCommented:
<a href="#" onClick="closeCurrentWin(true);">close me</a>
0
 
Ryan ChongCommented:
>><a href="#" onClick="closeCurrentWin(true);">close me</a>
It will be always a better pratice to have "return false;" along, right?

<a href="#" onClick="closeCurrentWin(true);return false;">close me</a>
0
 
frankybonesAuthor Commented:
thank you all for the many examples...please allow me some time to figure out wich one will work best for my application.  Thank you for you time and knowledge.

-FB
0
 
DJAriganCommented:
This doesn't need to be in a form.

<BUTTON TYPE="button" onClick="self.close();">Close</BUTTON>
0
 
frankybonesAuthor Commented:
I would like to thank everyone for their efforts and their knowledge once again.
After a lengthy test and trial I made my choice based my application, you all had
right answers.  Thank you,

-FB
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.