Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add constructor for BeforeUnloadEvent #2574

Closed
ayg opened this issue Apr 23, 2017 · 4 comments
Closed

Add constructor for BeforeUnloadEvent #2574

ayg opened this issue Apr 23, 2017 · 4 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: events

Comments

@ayg
Copy link
Contributor

ayg commented Apr 23, 2017

We normally allow authors to instantiate their own events (although I don't know why). These days we do this with constructors, so BeforeUnloadEvent should have a constructor. AFAICT, every other event type defined in the spec already has one.

@ayg
Copy link
Contributor Author

ayg commented Apr 23, 2017

(See whatwg/dom#445)

ayg added a commit to ayg/html that referenced this issue Apr 23, 2017
Fixes whatwg#2574.  This is consistent with all other event types defined in
the spec, and the way we do things today in general.
@zcorpan
Copy link
Member

zcorpan commented Apr 23, 2017

So this event was added in 246c3b4 which includes a note (still in the spec today)

+  <p class="note">There are no <code>BeforeUnloadEvent</code>-specific
+  initialization methods.</p>

email: https://lists.w3.org/Archives/Public/public-whatwg-archive/2008Dec/0146.html

irc ramblings: https://krijnhoetmer.nl/irc-logs/whatwg/20081212#l-99

So... at that time event constructors didn't exist. But at least it seems intentional to not include initBeoreUnloadEvent method.

If we add a constructor, you would be able to fire a beforeunload event (with the right interface) in onbeforeunload handler. Does the spec for handling this event need to change to avoid having the user get stuck with repeated dialogs, or something?

@ayg
Copy link
Contributor Author

ayg commented Apr 23, 2017

The constructor needn't allow you to initialize anything. It can take a plain EventInit dict, so it just lets you create it with no flags (beyond bubbles and cancelable, which you can set now with initEvent).

You can already fire a BeforeUnloadEvent in a beforeunload handler using createEvent(), in Chrome and Firefox. This is consistent with the way the rest of the platform works. Browsers already don't have to display the dialogs if they don't want to, so I think this can be left to a QoI issue, unless you have a specific concern that you think should be in the spec.

@zcorpan
Copy link
Member

zcorpan commented Apr 23, 2017

Oh I mistakenly thought "beforeunloadevent" was not in https://dom.spec.whatwg.org/#dom-document-createevent . Then I agree there are no new abilities.

Test for my scenario with createEvent: http://software.hixie.ch/utilities/js/live-dom-viewer/saved/5041

It seems the browsers I have don't show more than one dialog.

Looking at the spec, it's clear that the prompt can only appear because of the UA-generated event.

ayg added a commit to ayg/html that referenced this issue Aug 3, 2017
Fixes whatwg#2574.  This is consistent with the way events behave these days
in the platform.
@domenic domenic added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest labels Aug 3, 2017
@domenic domenic closed this as completed Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: events
Development

Successfully merging a pull request may close this issue.

3 participants