OnClose Event
Posted: Sat May 27, 2006 8:27 pm
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
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
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
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.
Code: Select all
<body onunload="opener.focus" onload="self.focus">That was what I was referring to.... it's ok you son't need to hard-code that into each hyperlink, you can javascript to do that hard work for youphppage wrote:Do you mean I would have to do a onclick event for every link on the page?
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>