Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts

    onload and onunload

    I have this function:
    Code:
    	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!

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    I tried it in my pages and your code works.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Here

    This is the file. can you see something problematic?
    Code:
    <!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

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    I don't see anything problematic.
    What do you mean by "nothing works"? The function is not triggered?

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    exactly.
    the popup (which it's code is attached above) is closed, but nothing happens in the window.opener (it's not refreshed).

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    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.
    Code:
    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();
      }
    }

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    no
    it seems like onunload is not working at all!


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

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Even the unloading message "unloading..." did not alert?
    Check the javascript console for possible errors.

  • #9
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    how can I check the JS console? Where is it?

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    I don't have firebird but it must be in the menu bar. Or you can try typing javascript&#58; in the address bar.

  • #11
    Regular Coder
    Join Date
    Jul 2002
    Posts
    436
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •