我刚刚开始使用 xCode 进行开发,因为我需要一个网站的 WebView 容器。 到目前为止它有效,但我无法在网站上注销,因为(在网络浏览器中)有一个弹出窗口询问我是否确定注销。我猜它是用 javascript 创建的。
在 Web View 设置中,有一个标记为“允许弹出窗口”的复选框,但在我的应用程序中,单击后不会出现弹出窗口。
我搜索了两个小时,没有找到与我的问题相关的类似内容。
最佳答案
这是javascript的confirm()函数。
我可以使用它:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[webView setUIDelegate:self]; // <------- This is an important part!!!
[[webView preferences] setJavaScriptEnabled:YES];
[[webView preferences] setJavaScriptCanOpenWindowsAutomatically:YES];
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:homeURLString]]];
}
和
- (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
NSInteger result = NSRunInformationalAlertPanel(NSLocalizedString(@"JavaScript", @""), // title
message, // message
NSLocalizedString(@"OK", @""), // default button
NSLocalizedString(@"Cancel", @""), // alt button
nil);
return NSAlertDefaultReturn == result;
}
关于javascript - OS X WebKit WebView 不显示 JS 弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24953510/