javascript - OS X WebKit WebView 不显示 JS 弹出窗口

标签 javascript webview xcode5

我刚刚开始使用 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;  
}

更多信息herehere .

关于javascript - OS X WebKit WebView 不显示 JS 弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24953510/

相关文章:

javascript - 仅使用 javascript 和 'this' 更改 img 源 onmouseover

javascript - GmailApp、getDate 和排序

android - 在 webview 中打开 url - phonegap

webview - 从<webview>截取对话框并读取内容

ios - 在 NavigationController 中推送多个 UIViewController

iphone - CGContextShowTextAtPoint 已弃用 - 我现在应该使用什么?

javascript - 我想要与该网站类似的效果。可以用 jQuery 来完成吗?

Javascript/Silverlight 代理双加载延迟

c# - 在代码中查找 Webview2 WPF 控件的边缘版本

ios - 为什么 Xcode 自动完成在导入时建议 .m 文件?