Closed Bug 681636 Opened 13 years ago Closed 2 years ago

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

Categories

(Core :: DOM: Core & HTML, defect)

defect

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: matutetandil, Unassigned)

References

Details

(Keywords: regression)

Attachments

(2 files)

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
Recently I test the issue in Firefox 3.0 and works, version 3.5.11 and 3.6.8 don't work
If I change the event onUnload with onBeforeUnload, it works OK...
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
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
}
(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)
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!
(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),
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),
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
This issue is still happening in FF9, FF10, FF12, and FF13.
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,
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..
Severity: normal → major
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.
(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
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?
(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.
Component: DOM → DOM: Core & HTML

I can't manage to reproduce this issue on my machines Win 10 and MacOS 11 on the latest Nightly. No alerts message received from accessing the html from the description and close both pages(pop-up and first page). Same behaviour on Chrome. Maybe the test case(html) should be updated.
Alice, is this issue still reproducible on the latest Nightly?
I noticed that Matias account is not active anymore.
Thanks.

Flags: needinfo?(alice0775)
Attached file Bug681636-p.html

Steps to reproduce:

  1. Open Browser Console(Ctrl+Shift+Alt+I) and Enable Show Content Messages
  2. Open attached Bug681636-p.html in a new tab
  3. Close the tab

Actual Results:
Browser Console does not output unload event detected!.

Expected Results:
Browser Console should output unload event detected!.

Flags: needinfo?(alice0775)

In the process of migrating remaining bugs to the new severity system, the severity for this bug cannot be automatically determined. Please retriage this bug using the new severity system.

Severity: major → --
Severity: -- → S3

The problem with the example in comment 20 is that the console.log API doesn't record the log call from the unload handler. An XHR triggered from the unload handler with the same STR does work, though, and triggers browser console output.

Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: