Apparently I need to call makeKeyAndOrderFront:
in webView:createWebViewWithRequest:
... the example here https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/DisplayWebContent/Tasks/MultipleWindows.html#//apple_ref/doc/uid/20002026-117294 implies that this is necessary (as openUntitledDocumentAndDisplay:error:
will call makeKeyAndOrderFront:
) while the documentation for webViewShow:
seems to imply that showing the window should be its responsibility exclusively. Confusing. If anyone has a better explanation, it's welcome.
Facebook like button not launching new window in Cocoa WebView
-
23-07-2023 - |
Pregunta
I'm using a Cocoa WebView which loads an HTML page containing social media buttons. When I click the Facebook like button, no popup window is opened at all, however others such as Twitter and Google+ work fine and launch the popup window as expected.
That same HTML page works without issue in Safari.
I believe I've implemented my WebUIDelegate properly and can't think of what else might be causing this issue. Any ideas?
#pragma mark WebViewUIDelegate Methods
- (WebView *)webView:(WebView *) __unused sender createWebViewWithRequest:(NSURLRequest *)request
{
NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 400, 300) styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask backing:NSBackingStoreBuffered defer:YES];
[window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
WebView *webView = [[WebView alloc] init];
[webView setFrameLoadDelegate:self];
window.contentView = webView;
[webView.mainFrame loadRequest:request];
[_popupWindows addObject:window];
return webView;
}
- (WebView *)webView:(WebView *)sender createWebViewModalDialogWithRequest:(NSURLRequest *)request
{
return [self webView:sender createWebViewWithRequest:request];
}
- (void)webViewRunModal:(WebView *)sender
{
[sender.window makeKeyAndOrderFront:self];
}
- (void)webViewShow:(WebView *)sender
{
[sender.window makeKeyAndOrderFront:self];
}
- (void)webViewClose:(WebView *)sender
{
[_popupWindows removeObject:sender.window];
[sender.window close];
}
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow