Last Comment Bug 669296 - event.preventDefault no longer works in DOMWillOpenModalDialog
: event.preventDefault no longer works in DOMWillOpenModalDialog
Status: NEW
: regression
Product: Thunderbird
Classification: Client Software
Component: General (show other bugs)
: Trunk
: All Other
: -- normal with 3 votes (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-07-05 06:44 PDT by M8R-948xqx
Modified: 2014-04-10 22:34 PDT (History)
7 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---


Attachments

Description M8R-948xqx 2011-07-05 06:44:31 PDT
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
Comment 1 Justin Dolske [:Dolske] 2011-08-14 16:04:33 PDT
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.
Comment 2 M8R-e2jp4 2012-02-11 04:32:52 PST
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.
Comment 3 inst 2013-04-17 01:44:29 PDT
Have you found the solution?

I believe this bug is still in Firefox, why was the Product switched to Thunderbird?
Comment 4 M8R-e2jp4 2013-04-17 03:37:34 PDT
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.
Comment 5 inst 2013-04-17 05:06:35 PDT
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
			button.doCommand();
			Services.obs.removeObserver(observer, "xul-window-visible");
		}
	}, "xul-window-visible", false)
, true);

Note You need to log in before you can comment on or make changes to this bug.