如何在Cocoa WebView中启用modaldialog

时间:2016-05-03 08:01:34

标签: ios objective-c macos

当我在HTML中加载包含ModalDialog的{​​{1}}页面时,根本没有打开任何弹出窗口。相同的WebView页面无问题在HTML。所以任何人都可以解决它?

以下是代码:

Safari

1 个答案:

答案 0 :(得分:0)

 #pragma -mark -WebView Delegate

- (WebView *)webView:(WebView *)sender createWebViewWithRequest:    (NSURLRequest *)request{
NSUInteger windowStyleMask = NSClosableWindowMask|NSMiniaturizableWindowMask|NSTitledWindowMask;
_webWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 400, 300) styleMask:windowStyleMask backing:NSBackingStoreNonretained defer:YES];
[_webWindow setReleasedWhenClosed:NO];
WebView* newWebView = [[WebView alloc] initWithFrame:[_webWindow contentRectForFrameRect:_webWindow.frame]];
[newWebView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[[newWebView mainFrame] loadRequest:request];
[_webWindow setContentView:newWebView];
[_webWindow center];
[_webWindow makeKeyAndOrderFront:nil];

return newWebView;

 }


 - (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{
[sender.window close];
}