OnClose Event
Moderator: General Moderators
OnClose Event
Could any one advise me if OnClose is a event handler in JS. Have seen it quoted on some sites but can not find it in http://www.w3schools.com
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
And depending upon what you need to do with most modern browsers are very restrictive over it. onbeforeunload, although non-standard works in FF and IE but the main purpose is for generating warning when a user is in the middle of something and tries to close the window.hawleyjr wrote:I think you're looking for:
onUnload not onClose
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
I bet that's one of those things that browsers will deny you access to using onunload.... could you imagine a cascade of annoying popups all bringing each other back into focus? It will require some use input I bet.phppage wrote:I tried onunload event but event was triggered everytime the user click a link on the website rather than closed it. What I want is for the parent window to focus when the child is closed.
Code: Select all
<script type="text/javascript">
<!--
function closeAndFocus()
{
if (window.opener) window.opener.focus();
window.close();
}
// -->
</script>
<a href="javascript:closeAndFocus();">Click here to close this window and return to your shopping cart</a>How would you go about differentiate between the window being closed and a link being selected by the user within that same window?feyd wrote:it's possible to detect if the window is being closed. onunload can be used for that purpose.
Tried it this way
Code: Select all
<body onunload="opener.focus" onload="self.focus">- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Something along the lines of:
That's pretty pseudo although it may just work - I haven't tested it.
Code: Select all
<script type="text/javascript">
<!--
function nullEvent()
{
window.onunload = false;
}
var links = document.getElementsByTagName('a');
for (var i in links)
{
if (links[i].captureEvent) links[i].captureEvent(CLICK);
links[i].onclick = nullEvent;
}
// -->
</script>