Closed Bug 1040281 Opened 10 years ago Closed 10 years ago

clicking back button after a post request to iframe does NOT fire onbeforeunload event

Categories

(Firefox :: Untriaged, defect)

30 Branch
x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: mike.mkrallaproductions, Unassigned)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:30.0) Gecko/20100101 Firefox/30.0 (Beta/Release)
Build ID: 20140605174243

Steps to reproduce:

1.) create form with target="my_iframe".
2.) create iframe with name="my_iframe".
3.) create script for main html document with:

window.onbeforeunload = function(){
  return "stop!";  
}

3.) submit form created in step 1.
4.) click back button.


Actual results:

after clicking the back button, the onbeforeunload NEVER fires. 
All other navigation fires the onbeforeunload event as expected: clicking any link, refreshing the page, etc.


Expected results:

the onbeforeunload event should fire just like all other navigation.
Whiteboard: post request
Whiteboard: post request
I'm confused. You're adding an onbeforeunload listener to the main document, but you expect it to fire for the unloading of the iframe?

This doesn't seem to work in current Firefox nor current Chrome, not even for clicking links in the iframe as you suggest. Do I misunderstand what you're trying to do?
Flags: needinfo?(mike.mkrallaproductions)
Keywords: testcase
I'm expecting it to fire after posting to the iframe, and then clicking the back button. And yes, Chrome does fire the event; I just tried it again to confirm.

Here, I've made it very easy for you to test:
http://jsfiddle.net/mkhirallah/Mm43Y/2/

Follow these steps exactly, in both Firefox and Then Chrome:
1.) Click the "post and load iframe" submit button.
2.) Click the back button

In Firefox, the event does not fire after clicking the back button. period.
In Chrome, the event DOES fire after clicking the back button. (I just tried it again as we speak).

I hope this helps
Flags: needinfo?(mike.mkrallaproductions)
(In reply to Mike from comment #2)
> I'm expecting it to fire after posting to the iframe, and then clicking the
> back button. And yes, Chrome does fire the event; I just tried it again to
> confirm.
> 
> Here, I've made it very easy for you to test:
> http://jsfiddle.net/mkhirallah/Mm43Y/2/
> 
> Follow these steps exactly, in both Firefox and Then Chrome:
> 1.) Click the "post and load iframe" submit button.
> 2.) Click the back button
> 
> In Firefox, the event does not fire after clicking the back button. period.
> In Chrome, the event DOES fire after clicking the back button. (I just tried
> it again as we speak).
> 
> I hope this helps

But in Chrome, the entire page (jsfiddle) unloads. In Firefox, the first time you click "back", it's just the frame that goes back a page... If you type a different address in the address bar, you get an onbeforeunload prompt just fine.

onbeforeunload doesn't bubble through from the different frame, and you're attaching a listener to the parent page.

I don't think there's actually a web compat issue here - just a difference as to what the browser's UI elements do...
OK - but the difference that actually matters is that in Firefox, the onbeforeunload event does NOT fire after the back button is clicked in the example, whereas in Chrome, it does fire. This is a pretty large discrepancy I would think, but I've revamped my implementation to avoid the use of iframes anyways (because I've never liked them and my previous requirement to use them was changed to optional, thank God).

I recognize that its neither the fault of Firefox or Chrome with regards to the different behavior, I just needed to point out the inconsistency and let you decide if it was the preferred behavior of Firefox to not fire the event.

I'm going to close this bug report even though it might come up for someone else posting to iframes and dealing with back button clicks/onbeforeunload events, so it is at least documented.
Status: UNCONFIRMED → RESOLVED
Closed: 10 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.