...

View Full Version : onload and onunload



ShMiL
03-16-2004, 03:03 PM
I have this function:


function closeAndRefresh() {
if (window.opener && !window.opener.closed) {
window.opener.location.reload();
window.opener.focus();
}
}


When I use it onload, everythings works great.
When I use it onUNload, nothing works.

If things like that doesn't work on onunload, so what's the use of it?

Thanks!

glenngv
03-17-2004, 04:48 AM
I tried it in my pages and your code works.

ShMiL
03-17-2004, 08:15 AM
This is the file. can you see something problematic?



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<STYLE TYPE="text/css">
td {
font-family:arial,tahoma,miriam;
font-size:10pt;
}
body {
direction:rtl;
cursor:default;
margin:0px;
}
td.box {
text-align:center;
width:50px;
height:50px;
background-color:#404040;
color:#404040;
font-size:24pt;
font-weight:bold;
border:20px outset #FF6D15;
}
</STYLE>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=windows-1255">
<title>בדרך לאילת - פנסיון ומספרה לכלבים :: הגרלת שק בונזו</title>
<meta name="Author" content="Shmulik Simchony">
<meta name="Keywords" content="">
<meta name="DESCRIPTION" content="">
<script type="text/javascript">
function closeAndRefresh() {
if (window.opener && !window.opener.closed) {
window.opener.location.reload();
window.opener.focus();
}
}
var box1=0;
var box2=0;
var box3=0;
var msg;
var informed=0;
function revealer (where) {
where.style.background='#FFCD7D';
if (where.id=='box1' && box1!=1) {
box1=1;
}
if (where.id=='box2' && box2!=1) {
box2=1;
}
if (where.id=='box3' && box3!=1) {
box3=1;
}
if (box1==1 && box2==1 && box3==1 && informed==0) {
informed=1;
msg = 'לא זכית. לא נורא\n\nתודה שהשתתפת';
setTimeout("alert(msg);", 1500);
}
}
</script>
</head>
<body onunload="closeAndRefresh();">
<table style="margin:auto;height:120px;">
<tr><td class="box" onClick="revealer (this);" id="box1">8</td><td class="box" onClick="revealer (this);" id="box2">9</td><td class="box" onClick="revealer (this);" id="box3">6</td></tr><tr><td colspan="3" style="height:20px;">יש ללחוץ על שלושת התיבות כדי לחשוף את המספרים.</td></tr>
</table>
</body>
</html>


Thanks

glenngv
03-17-2004, 09:09 AM
I don't see anything problematic.
What do you mean by "nothing works"? The function is not triggered?

ShMiL
03-17-2004, 09:10 AM
exactly.
the popup (which it's code is attached above) is closed, but nothing happens in the window.opener (it's not refreshed).

glenngv
03-17-2004, 10:38 AM
try this while the opener is open to check if the onunload handler is triggered or not and if opener is still alive and open.


function closeAndRefresh() {
alert("unloading...");
alert(window.opener && !window.opener.closed);//must be true
if (window.opener && !window.opener.closed) {
window.opener.location.reload();
window.opener.focus();
}
}

ShMiL
03-17-2004, 10:50 AM
no
it seems like onunload is not working at all!
:(

PS
the opener is open (true) - I tested it on 'onload'

glenngv
03-17-2004, 11:06 AM
Even the unloading message "unloading..." did not alert?
Check the javascript console for possible errors.

ShMiL
03-17-2004, 11:14 AM
how can I check the JS console? Where is it?

glenngv
03-17-2004, 11:55 AM
I don't have firebird but it must be in the menu bar. Or you can try typing javascript&#58; in the address bar.

ShMiL
03-17-2004, 12:25 PM
GOD!
You'll never guess what was the problem!!!

I couldn't find errors at all, so I googled this: 'onunload="javascript' and the first result gave me the answer!
The problem is the Google Toolbar! It's popup blocker, assumes that onunload events will probably be popups - so it blocks it.

After disabling the popup blocker - everything's working great.

Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum