RESOLVED WONTFIX 48231
Cannot close modal windows from javascript
https://bugs.webkit.org/show_bug.cgi?id=48231
Summary Cannot close modal windows from javascript
Christiaan Hofman
Reported 2010-10-25 05:04:33 PDT
A modal window that was created using javascript showModalDialog() cannot be closed from javascript close(). The reason is that it puts a delayed _closeWindow message with the default run loop, however this will never be called when there is a modal window currently active. See bug 40036 for more details. That bug was closed because some other bug (bug 35350) was resolved in a different way. However, that is no reason to discard the bug, because the problem is still relevant for actual applications using WebKit (the test from bug 35350 is not the only place where modal dialogs are used, they're also used in the REAL WORLD, where they still not work). I don't know what Safari does to make modal windows work, but you could have a look in their code to fix this.
Attachments
Test case of a simple WebKit browser allowing modal dialogs (22.99 KB, application/zip)
2010-10-25 13:41 PDT, Christiaan Hofman
no flags
Alexey Proskuryakov
Comment 1 2010-10-25 10:07:56 PDT
Could you please attach a test case that works in other browsers? I understand that it might be there in some of the related bugs that you mentioned, but it's better to have all relevant information in one place, and not scattered all over Bugzilla.
Christiaan Hofman
Comment 2 2010-10-25 10:33:09 PDT
I am not sure what you mean by a test case, or "other browsers". But it is not working for any basic browser app (for instance a small extension of Apple's MiniBrowser sample) that implements the WebUIDelegate methods webViewShow:, webViewClose: webViewRunModal:, and webView:createWebViewModalDialogWithRequest: in a meaningful (and straight forward) way. For instance with this simple extension of the sample code in Apple's documentation for multiple windows" - (WebView *)webView:(WebView *)sender createWebViewModalDialogWithRequest:(NSURLRequest *)request { // really the same as webViewShow: id myDocument = [[NSDocumentController sharedDocumentController] openUntitledDocumentOfType:@"DocumentType" display:YES]; if (request) [[[myDocument webView] mainFrame] loadRequest:request]; return [myDocument webView]; } - (void)webViewShow:(WebView *)sender { id myDocument = [[NSDocumentController sharedDocumentController] documentForWindow:[sender window]]; [myDocument showWindows]; } - (void)webViewRunModal:(WebView *)sender { // ivar to keep track whether we are running a modal window isModal = YES; [NSApp runModalForWindow:[sender window]]; } - (void)windowWillClose:(NSNotification *)notification { // assume this is the window delegate, and stop running modal if necessary if (isModal) [NSApp stopModal]; } Load a page that includes a showModalDialog() javascript action tied to a link or button, for instance with this simple HTML: <html> <a href="javascript:showModalDialog('dialog.html')">Show Modal Dialog</a> </html> And let the dialog (dialog.html) contain a link or button tied to the javascript close() action, for instance with this HTML: <html> <a href="javascript:close()">Close</a> </html> Really nothing else should be required to see it. I don't know why it does work in Safari, there must be a serious workaround there, because it does not work with plain WebKit and proper delegate method implementations, and that's what matters.
Christiaan Hofman
Comment 3 2010-10-25 13:41:52 PDT
Created attachment 71791 [details] Test case of a simple WebKit browser allowing modal dialogs
Ahmad Saleem
Comment 4 2022-07-31 02:29:37 PDT
showModalDialog support is gone from other browser and recently from Webkit Github source as well: https://github.com/WebKit/WebKit/commit/c4bb4d1af89e1ef5f57ef1b1cf7b65ce62c30ba5 Do we need to work on this? Thanks!
Note You need to log in before you can comment on or make changes to this bug.