Solved

script to close self browser window

Posted on 2004-04-15
9
1,649 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 50

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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 35

Accepted Solution

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

closeCurrentWin( true)
0
 
LVL 35

Expert Comment

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

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

776 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