Closed Bug 669296 Opened 13 years ago Closed 4 years ago

event.preventDefault no longer works in DOMWillOpenModalDialog


(Thunderbird :: General, defect)

Not set


(Not tracked)



(Reporter: M8R-948xqx, Unassigned)


(Keywords: regression)

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/10.10 Chromium/12.0.742.91 Chrome/12.0.742.91 Safari/534.30

Steps to reproduce:

When I used event.preventDefault after hearing the DOMWillOpenModalDialog event in Firefox versions < 4.0 the DOM dialog did not open.

Actual results:

In Version 4.0 and above, calling event.preventDefault has no effect on the modal dialog, even though it should prevent the dialog from appearing.

furthermore, event.cancelable is true

Expected results:

the dialog should not be created at all
Hmm. nsPrompter.js :: fireDialogEvent() just fires the event and moves on. I remember this issue coming up, but I thought we were still supporting it... Guess not!

What are you using this event for?

Long term, the idea was to make is a notification instead of a DOM event.
Component: Extension Compatibility → General
Ever confirmed: true
Product: Firefox → Thunderbird
QA Contact: extension.compatibility → general
Version: 4.0 Branch → Trunk
I am using this event for cancelling the Modal Dialog. This is necessary for a feature in an extension i am building. Having the ability to prevent the modal dialog from popping up is a feature which in my case is very useful and convenient. Having it removed/malfunction is a deal-breaker in my case.

In any case, I think it should be treated as a DOM Event and should be cancelable, like it was when it was still working.
Have you found the solution?

I believe this bug is still in Firefox, why was the Product switched to Thunderbird?
There is no solution as of yet, only workarounds for specific cases.

The bug is in Firefox indeed, I don't know why it was switched to Thunderbird.
Thanks for your reply!

So, for those who will stumble upon this bug in future and need any solution to simply dismiss dialogs from chrome code here is quick workaround I came to:

gBrowser.selectedBrowser.addEventListener("DOMWillOpenModalDialog", function (e)
	Services.obs.addObserver(function observer (subject, topic, data) {
		// hacky way to get dialog chrome window,
		// subject and data are both null here
		let window = Services.wm.getMostRecentWindow(null)
		  , document = window.document.documentElement
		  , button = document.getButton("accept");
		if (button) {
			// we now sure that we got kind of dialog
			Services.obs.removeObserver(observer, "xul-window-visible");
	}, "xul-window-visible", false)
, true);

This doesn't seem like a bug so much as it's a change to code that the OP wanted to work around. Is it still valid or perhaps is it fixed in newer TB version?

Flags: needinfo?(M8R-948xqx)

Closing as WFM and the OP didn't respond after 1 year. Reopen if it's still present.

Closed: 4 years ago
Resolution: --- → WORKSFORME
Flags: needinfo?(M8R-948xqx)
You need to log in before you can comment on or make changes to this bug.