Instance Method

webView(_:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:completionHandler:)

Displays a JavaScript text input panel.

Declaration

optional func webView(_ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (String?) -> Void)

Parameters

webView

The web view invoking the delegate method.

prompt

The message to be displayed.

defaultText

The initial text to display in the text entry field.

frame

Information about the frame whose JavaScript process initiated this call.

completionHandler

The completion handler to call after the text input panel has been dismissed. Pass the entered text if the user chose OK, otherwise nil.

Discussion

For user security, implementations of this method should call attention to the fact that a specific website controls the content in this panel. A simple formula for identifying the controlling website is frame.request.URL.host. The panel should have two buttons (typically OK and Cancel) and a field in which to enter text.