Page 1 of 1
Need Javascript
Posted: Wed Apr 16, 2003 1:25 am
by vram
Hi friends
I want to perform the following actions.
1.I want a script to run when the user closes the window either by pressing ALt+F4 or pressing the X at the top right corner.
(actually i want a php system fn to run when the abv action takes place.)
2.I used anchor text in my site .I want the users to open the link in the same window not allowing them to open in new window which they do either by pressing shif+Mouseclick or right click and choose open in new window option.Can anyone help me.
thanx in advance for ur suggestions.
bye
Posted: Wed Apr 16, 2003 2:18 am
by EvilWalrus
whether it's done with PHP piped through javascript is totally redundant, once a window is closed, it's closed... until the user reopens the application, which, sorry to say, you have absolutely no control over. Correct me if i'm wrong, but what you're proposing is impossible.
Posted: Wed Apr 16, 2003 6:59 am
by patrikG
If I understood you right, use "<body onUnload='mySubmitFunction()'>" so that Javascript would transmit data to the server (i.e. PHP).
For part 2 of your question: I don't quite see how that ties in with part 1 - do you want the page to open in the window that was just closed? If so: sorry, mate, impossible.
If you just want to prevent someone from changing the "target='..'" in your <a href=>" use a form-button with an onClick-event.
Not sure if that is entirely what you were looking for...
Re
Posted: Tue Apr 22, 2003 1:31 am
by vram
Hi
I clarify u.I want a PHP system function to be called when the user performs the following actions only.
He closes the window either by pressing X or presing Alt+F4.Unload fn will be called everytime i move from that page to anyother page.Inthat case i dont want to call system fn since im not out of my session.Hope i made u clear or else revert me back.Bye
Thanx in adv for ur suggestions
patrikG wrote:If I understood you right, use "<body onUnload='mySubmitFunction()'>" so that Javascript would transmit data to the server (i.e. PHP).
For part 2 of your question: I don't quite see how that ties in with part 1 - do you want the page to open in the window that was just closed? If so: sorry, mate, impossible.
If you just want to prevent someone from changing the "target='..'" in your <a href=>" use a form-button with an onClick-event.
Not sure if that is entirely what you were looking for...
Posted: Tue Apr 22, 2003 2:05 am
by patrikG
You can check whether a window Javascript has opened is still open.
With onUnload in the child-window that calls the check-function in the parent-window it's probably as close as you can get to what you want.
Code: Select all
<html><head><title>Test</title>
<script type="text/javascript">
<!--
var myWin = window.open("test.html", "2nd window");
function CheckOpen()
{
if(myWin.closed == true) alert("Window has been closed");
else alert("Window still open");
}
//-->
</script>
</head><body>
<a href="javascript:CheckOpen()">Close Window?</a>
</body></html>