2
votes

I use WKWebView to show a web page. When I touch a button on the page, some javascript code should work and show me an alert view. But it doesn't work. If I open the page on Safari, it works well. Here is my code

WKWebViewConfiguration *configuration = [WKWebViewConfiguration new];
configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
configuration.preferences.javaScriptEnabled = YES;

_webView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:configuration];
self.view = _webView;
NSURLRequest *req = [NSURLRequest requestWithURL:[HPBNetworkBusiness getExamPageURL]];
[_webView loadRequest:req];
[_webView addObserver:self forKeyPath:@"URL" options:NSKeyValueObservingOptionNew context:nil];
1

1 Answers

3
votes

WKWebView will not show JavaScript alerts automatically. It will be notified through webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler: defined on WKUIDelegate. You can use the information passed in to show a native alert using UIAlertController.