前提・実現したいこと
WKWebViewベースのiPhoneアプリを作っているのですが、[swift] WKWebViewでhtml formのsubmitボタンが反応しないので反応するようにしたいです。ご教授の程をお願いいたします。
現状のswiftコード(FirstViewController.swift)は以下になります。
import UIKit import WebKit class FirstViewController: UIViewController, WKUIDelegate { var webView: WKWebView! override func loadView() { let webConfiguration = WKWebViewConfiguration() webView = WKWebView(frame: .zero, configuration: webConfiguration) webView.uiDelegate = self view = webView } override func viewDidLoad() { super.viewDidLoad() self.webView.allowsBackForwardNavigationGestures = true let myURL = URL(string:"http://13.231.195.30") let myRequest = URLRequest(url: myURL!) webView.load(myRequest) } // target blank link fix (open safari, otherwise open app) func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? { if navigationAction.targetFrame == nil { // webView.load(navigationAction.request) UIApplication.shared.open(navigationAction.request.url!, options: [:]) //for enable safari } return nil } func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) { let alertController = UIAlertController(title: "", message: message, preferredStyle: .alert) let otherAction = UIAlertAction(title: "OK", style: .default) { action in completionHandler() } alertController.addAction(otherAction) present(alertController, animated: true, completion: nil) } }
あなたの回答
tips
プレビュー