JavaScript alert() not working in embedded WebView

前端 未结 2 1551
渐次进展
渐次进展 2020-12-18 22:52

When embedding WebView in an application and loading html-pages in it, JavaScripts alert()/confirm()/etc. do not work.

Looking around in th

相关标签:
2条回答
  • 2020-12-18 23:00

    It turns out there is simply no default WebUIDelegate set - Apple seems to expect everyone to implement the same basic features for themselves.

    0 讨论(0)
  • 2020-12-18 23:16

    Here is a sample code that will do the basic job. You need however to make sure that this object is registered as a UIDelegate for the WebView.

    - (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
        NSAlert *alert = [[NSAlert alloc] init];
        [alert addButtonWithTitle:@"OK"];
        [alert setMessageText:message];
        [alert runModal];
        [alert release];
    }
    
    0 讨论(0)
提交回复
热议问题