OnClose Event

JavaScript and client side scripting.

Moderator: General Moderators

User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

phppage wrote:Thanks for that, will give it a go and let you know :D
I'd stick it in a function that runs onload in the body. If you put it in the head just like that it won't work because "document" isn't finished loading.

It'll almost certainly need some fixing.
User avatar
phppage
Forum Contributor
Posts: 126
Joined: Mon Apr 24, 2006 1:47 pm
Location: West Yorkshire, UK

Post by phppage »

It only seems to work in Netscape, not IE. Is captureEvent valid in IE do you know?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Oops sorry typo there - it's captureEvents().
User avatar
phppage
Forum Contributor
Posts: 126
Joined: Mon Apr 24, 2006 1:47 pm
Location: West Yorkshire, UK

Post by phppage »

You are a star, got it to work with very little tweaking. Here is the final code

Code: Select all

<script language="Javascript" type="text/javascript">


function nullEvent()
{
    window.onunload = null;
}

function correctlinks() {
var links = document.getElementsByTagName('a');

for (var i in links)
{
    if (links[i].captureEvents) links[i].captureEvents(CLICK);

    links[i].onclick = nullEvent;
}
 }
</script>
</head><body onunload="window.opener.focus();" onload="correctlinks();" >
Thanks for your help.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Glad you got it working :)
Post Reply