Last Comment Bug 681636 - window.onUnload don't work when the page is in a popup
: window.onUnload don't work when the page is in a popup
Status: NEW
: regression
Product: Core
Classification: Components
Component: DOM (show other bugs)
: Trunk
: All All
: -- major with 5 votes (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
:
Mentors:
: 1247945 (view as bug list)
Depends on:
Blocks: 465993
  Show dependency treegraph
 
Reported: 2011-08-24 07:01 PDT by Matias
Modified: 2016-05-22 23:29 PDT (History)
13 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
this is not testcase, just for comment7 (420 bytes, text/html)
2011-08-24 12:05 PDT, Alice0775 White
no flags Details

Description Matias 2011-08-24 07:01:50 PDT
User Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1

Steps to reproduce:

I have a page that opens another page in a popup window... the second page has an event that must run when the popup is closed (i do that with window.onUnload, or window.onBeforeUnload), thats don't works on Firefox 5 and 6, but works on Firefox 3.

Here is the code of both pages:
Page 1:
<html>
<head>

<title>onunload test</title>

<script type="text/javascript">
open("test.html","John","toolbar=0"); 
</script>
</head>

<body>
<p>popup</p>
</body>
</html>

Page 2:
<html>
<head>

<title>onunload test</title>

<script type="text/javascript">

window.onunload = unloadPage;

function unloadPage()
{
 alert("unload event detected!");
}
</script>
</head>

<body>
<p>Reload a new page into the browser<br />
 to fire the unload event for this page.</p>
<p>You can also use the back or forward buttons<br />
 to load a new page and fire this event.</p>
</body>
</html>


Actual results:

The event don't get firered... so nothing happens. I tried putting the event on the body, but nothing happens.


Expected results:

The event should be firered
Comment 1 Matias 2011-08-24 07:32:04 PDT
Recently I test the issue in Firefox 3.0 and works, version 3.5.11 and 3.6.8 don't work
Comment 2 Matias 2011-08-24 08:12:26 PDT
If I change the event onUnload with onBeforeUnload, it works OK...
Comment 3 Alice0775 White 2011-08-24 08:26:38 PDT
Confirmed on 
http://hg.mozilla.org/mozilla-central/rev/198c7de0699d
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0a1) Gecko/20110824 Firefox/9.0a1 ID:20110824030813

And an error in Error Console:

Error: uncaught exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIWindowWatcher.openWindow]"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  location: "JS frame :: resource:///components/nsPrompter.js :: openModalWindow :: line 416"  data: no]

Regression window(m-c nightly):
Works:
http://hg.mozilla.org/mozilla-central/rev/9dbded90af2a
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2a1pre) Gecko/20090113 Firefox/3.2a1pre ID:20090113035246
Fails:
http://hg.mozilla.org/mozilla-central/rev/89811ac1b35a
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2a1pre) Gecko/20090114 Firefox/3.2a1pre ID:20090114034711
Pushlog:
http://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=9dbded90af2a&tochange=89811ac1b35a
Triggered by:
8dae102faa15	Boris Zbarsky — Bug 465993. When opening a dependent window with an invisible non-chrome parent, throw. r=jst,ere, sr=jst
Comment 4 Matias 2011-08-24 09:55:19 PDT
It's really weird, but the only way that I found to get the code inside the function that i called when the popup close works its to put an alert at the end. Otherwise don't work
ie:
funtion xx(){
    ...
    some code
    ...
    alert("bla bla bla"); //if I comment the alert, the code don't work
}
Comment 5 Matias 2011-08-24 10:48:14 PDT
(In reply to Matias from comment #4)
> It's really weird, but the only way that I found to get the code inside the
> function that i called when the popup close works its to put an alert at the
> end. Otherwise don't work
> ie:
> funtion xx(){
>     ...
>     some code
>     ...
>     alert("bla bla bla"); //if I comment the alert, the code don't work
> }

This is not an error... i find a solution to that... sorry... (no needs the alert)
Comment 6 Boris Zbarsky [:bz] (TPAC) 2011-08-24 11:46:48 PDT
This sounds like expected behavior: parenting a modal dialog to an already-closed window is not allowed....  The event handler works fine; what you can't do is open an alert from it!
Comment 7 Alice0775 White 2011-08-24 12:05:55 PDT
Created attachment 555484 [details]
this is not testcase, just for comment7

(In reply to Boris Zbarsky (:bz) from comment #6)
> This sounds like expected behavior: parenting a modal dialog to an
> already-closed window is not allowed....  The event handler works fine; what
> you can't do is open an alert from it!

How about the following case?

[STR]
1 Start Firefox
2 Open attachment in first Tab
3 Open attachment in second Tab

4 Press Ctrl+w
5 Press Ctrl+w

[ACTUAL]
After step 4, you got an alert box.
But step 5, no alert box pops up and close window.

[EXPECTED]
I think both step should be same behavior (an alert box should appears),
Comment 8 Matias 2011-08-24 13:01:38 PDT
Yes... that's right... the problem is that firefox seems not to handle the onUnload event in a Popup...

(In reply to Alice0775 White from comment #7)
> Created attachment 555484 [details]
> this is not testcase, just for comment7
> 
> (In reply to Boris Zbarsky (:bz) from comment #6)
> > This sounds like expected behavior: parenting a modal dialog to an
> > already-closed window is not allowed....  The event handler works fine; what
> > you can't do is open an alert from it!
> 
> How about the following case?
> 
> [STR]
> 1 Start Firefox
> 2 Open attachment in first Tab
> 3 Open attachment in second Tab
> 
> 4 Press Ctrl+w
> 5 Press Ctrl+w
> 
> [ACTUAL]
> After step 4, you got an alert box.
> But step 5, no alert box pops up and close window.
> 
> [EXPECTED]
> I think both step should be same behavior (an alert box should appears),
Comment 9 cang 2012-06-17 19:29:42 PDT
This issue is still happening in FF9, FF10, FF12, and FF13.
Comment 10 paul tierney 2012-09-05 05:42:03 PDT
is this related to my problem at all please?

https://getsatisfaction.com/mozilla_messaging/topics/error_sending_mail_without_opening_modal_window?rfm=1
Comment 11 nandha 2013-06-09 23:59:53 PDT
any update on this issue?
Summary: window.onUnload and window.onBeforeUnload don't work when the page is in a popup → window.onUnload don't work when the page is in a popup

need to clear session from popup when window is unloading.

Thanks,
Comment 12 chandleg 2015-02-19 14:23:34 PST
4 years on, and this is still broken...
Sample Code:
window.onbeforeunload = function() 
  {
    return "Refreshing this page will duplicate your requests, please refrain from doing so!";
  }

When used the page does not inherit the custom message, and instead returns the default message from Firefox:
"This page is asking you to confirm that you want to leave - data you have entered may not be saved."
With the "Leave Page" and "Stay on Page" buttons.

It can't be that hard to add a conditional to check for the existence of a set return, and then inherit that as the dialog text, rather than always spew a static string..
Comment 13 Loic 2016-02-12 07:12:28 PST
*** Bug 1247945 has been marked as a duplicate of this bug. ***
Comment 14 Sandeep Pareek 2016-02-15 07:06:05 PST
hi, 
I am facing this problem in current release version 44.0.2.
Scenario:

I try to open a window using parameters. Window opens correctly.
but when I close the window using onbeforeunload(), the method that I intend to execute underneath doesn't fire.
This above problem is not faced when the same page is not opened in wiondow. onbeforeunload works correctly there.

I have seen  bug-1247945 which is marked as dupe. This bug status is marked as NEW. Shall I consider that It's not fixed at all? Or am I missing any piece here? 
Thank you.
Comment 15 Jacopo Tediosi 2016-02-15 07:09:58 PST
(In reply to Sandeep Pareek from comment #14)
> hi, 
> I am facing this problem in current release version 44.0.2.
> Scenario:
> 
> I try to open a window using parameters. Window opens correctly.
> but when I close the window using onbeforeunload(), the method that I intend
> to execute underneath doesn't fire.
> This above problem is not faced when the same page is not opened in wiondow.
> onbeforeunload works correctly there.
> 
> I have seen  bug-1247945 which is marked as dupe. This bug status is marked
> as NEW. Shall I consider that It's not fixed at all? Or am I missing any
> piece here? 
> Thank you.

It's not fixed yet
I am very disappointed by Firefox
Comment 16 Ivan Pozdeev 2016-05-22 07:29:26 PDT
Invalid.

In the original example, `alert()` is ignored in unload handler as per https://developer.mozilla.org/en-US/docs/Web/Events/unload .

The `beforeunload` issue from comment14 is irrelevant to this ticket.
Comment 17 Masatoshi Kimura [:emk] 2016-05-22 18:13:59 PDT
(In reply to Ivan Pozdeev from comment #16)
> The `beforeunload` issue from comment14 is irrelevant to this ticket.

Then is bug 1247945 misduped?
Comment 18 Ivan Pozdeev 2016-05-22 23:29:59 PDT
(In reply to Masatoshi Kimura [:emk] from comment #17)
> (In reply to Ivan Pozdeev from comment #16)
> > The `beforeunload` issue from comment14 is irrelevant to this ticket.
> 
> Then is bug 1247945 misduped?

No. It deals with `alert()` in onunload handler, too.

Note You need to log in before you can comment on or make changes to this bug.