Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simply just close the browser

Status
Not open for further replies.

zyrag

IS-IT--Management
Dec 4, 2002
252
PH
hi, i haven't tried javescript yet, and i know it's the answer for this question. Can somebody share to me a code snippet on closing the browser upon clicking the "exit" button or the "close" keyword on the page?

thanks,
 
im a little rusty on javascript, but i believe its:

window.close();
 
thanks dogers, how exactly do i place it in my PHP to simulate closing the page upon clicking the button with 'exit' value?

 
<a href=&quot;javascript:void(0) onclick=&quot;window.close(); return false&quot;>EXIT</a>

if its in PHP you will have to escape the &quot;'s

<a href=\&quot;javascript:void(0) onclick=\&quot;window.close(); return false\&quot;>EXIT</a>

also IE give the user a warning if the window it is closing is not a popup window, i.e. the main website that opened when the visitor typed the url in. so this works perfect for anything opened by a button/script from the main site and not so good for the main site. I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
 
I would assume that javascript:void(0) was meant to have marks both sides, ie

&quot;javascript:void(0)&quot;
 
php code for a button, is:
Code:
echo(&quot;<input type='button' onclick='javascript:window.close();' value='Exit'>\n&quot;);
 
onclick='' wont work on all browsers, it has to be onclick=&quot;&quot; so you have to escape the &quot; with \&quot; in php.

and yes it has to be &quot;javascript:void(0)&quot; I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
 
Way off topic for the PHP forum... but if you don't want to warn the user... and you don't want to escape the &quot;'s do this. This is tested in Mozilla and IE.

----------In the head of your file----------
Code:
echo '
<script language = &quot;javascript&quot;>
function bye() {
  self.opener=this;
  self.close();
}
</script>
';

and then the button

echo '<input type=&quot;button&quot; onclick=&quot;bye();&quot;>';
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top