Solved

script to close self browser window

Posted on 2004-04-15
9
1,647 Views
Last Modified: 2010-04-06
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
0
Comment
Question by:frankybones
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 10835787
try use window.close() ?

example:

<input type="button" name="Button" value="Close" onclick="window.close()">
0
 
LVL 2

Expert Comment

by:Fataqui
ID: 10836053
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
 
LVL 35

Expert Comment

by:YZlat
ID: 10836648
use self.close();


function closeCurrentWin( closeSelf){
      if(closeSelf) self.close();
}
0
 
LVL 35

Accepted Solution

by:
YZlat earned 215 total points
ID: 10836655
call this function the following way:

closeCurrentWin( true)
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 35

Expert Comment

by:YZlat
ID: 10836666
<a href="#" onClick="closeCurrentWin(true);">close me</a>
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 10839811
>><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
 

Author Comment

by:frankybones
ID: 10843479
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
 

Expert Comment

by:DJArigan
ID: 10871752
This doesn't need to be in a form.

<BUTTON TYPE="button" onClick="self.close();">Close</BUTTON>
0
 

Author Comment

by:frankybones
ID: 10883328
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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now