Note: There are a few cases of duplicates in user autocompletion which are being worked on.

window.onUnload don't work when the page is in a popup

NEW
Unassigned

Status

()

Core
DOM
--
major
6 years ago
a year ago

People

(Reporter: Matias, Unassigned)

Tracking

({regression})

Trunk
regression
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

6 years ago
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
(Reporter)

Comment 1

6 years ago
Recently I test the issue in Firefox 3.0 and works, version 3.5.11 and 3.6.8 don't work
(Reporter)

Comment 2

6 years ago
If I change the event onUnload with onBeforeUnload, it works OK...

Comment 3

6 years ago
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
Blocks: 465993
Status: UNCONFIRMED → NEW
Component: General → DOM
Ever confirmed: true
Keywords: regression
OS: Windows XP → All
Product: Firefox → Core
QA Contact: general → general
Hardware: x86 → All
(Reporter)

Comment 4

6 years ago
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
}
(Reporter)

Comment 5

6 years ago
(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

6 years ago
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

6 years ago
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),
(Reporter)

Comment 8

6 years ago
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),
(Reporter)

Updated

6 years ago
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

Comment 9

5 years ago
This issue is still happening in FF9, FF10, FF12, and FF13.

Comment 10

5 years ago
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

4 years ago
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

2 years ago
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..

Updated

a year ago
Duplicate of this bug: 1247945
(Reporter)

Updated

a year ago
Severity: normal → major

Comment 14

a year ago
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

a year ago
(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

a year ago
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.
(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

a year ago
(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.
You need to log in before you can comment on or make changes to this bug.