Ios 如何实施";您确定要再次提交表单吗;在WKWebView中
在Safari中,尝试重新加载表单时会显示警告,而WKWebView在重新加载时不会显示警告 如何实现“是否确定要再次提交表单”Ios 如何实施";您确定要再次提交表单吗;在WKWebView中,ios,swift,wkwebview,Ios,Swift,Wkwebview,在Safari中,尝试重新加载表单时会显示警告,而WKWebView在重新加载时不会显示警告 如何实现“是否确定要再次提交表单” 您可以轻松添加警报,创建UIAlertController,然后向其添加自定义操作 以您的情况为例: //Create the alert using UIAlertController. Add your custom title and custom message let alert = UIAlertController(title: "Information
您可以轻松添加警报,创建UIAlertController,然后向其添加自定义操作 以您的情况为例:
//Create the alert using UIAlertController. Add your custom title and custom message
let alert = UIAlertController(title: "Information", message: "Are you sure you want to submit the form again", preferredStyle: .alert)
//Add custom buttons with different style
alert.addAction(UIAlertAction(title: "Submit", style: .default, handler: nil))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
//Present the alertView
self.presentViewController(alert, animated: true, completion: nil)
您可以将其作为一个函数,然后在刷新页面时调用它。您可以轻松添加警报创建UIAlertController,然后向其添加自定义操作 以您的情况为例:
//Create the alert using UIAlertController. Add your custom title and custom message
let alert = UIAlertController(title: "Information", message: "Are you sure you want to submit the form again", preferredStyle: .alert)
//Add custom buttons with different style
alert.addAction(UIAlertAction(title: "Submit", style: .default, handler: nil))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
//Present the alertView
self.presentViewController(alert, animated: true, completion: nil)
您可以将其作为一个函数,然后可以在刷新页面时调用它。实现WKNavigationDelegate\webView(uu:DecisionPolicyFor:decisionHandler:) 然后,如果navigationAction.navigationType是FormResubmited,则显示警报 对于警报的提交或取消按钮操作,分别调用decisionHandler(.allow)或decisionHandler(.cancel)
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if case .formResubmitted = navigationAction.navigationType {
// Show alert
}
}
实现WKNavigationDelegate#webView(uuU2:DecisionPolicyFor:decisionHandler:) 然后,如果navigationAction.navigationType是FormResubmited,则显示警报 对于警报的提交或取消按钮操作,分别调用decisionHandler(.allow)或decisionHandler(.cancel)
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if case .formResubmitted = navigationAction.navigationType {
// Show alert
}
}
非常感谢。我想知道我何时尝试重新加载已发送的表单。您可以创建一个函数,例如,当用户按下“重新加载按钮”时,webView将被重新加载,并显示警报消息。您只需从webView出口调用reload the webView,如“webView.reload()”,然后在这行代码下面添加我在上面编写的警报函数。我想知道用户是要重新加载表单还是其他表单。此警报可防止表单的双重传输。谢谢!我想知道我何时尝试重新加载已发送的表单。您可以创建一个函数,例如,当用户按下“重新加载按钮”时,webView将被重新加载,并显示警报消息。您只需从webView出口调用reload the webView,如“webView.reload()”,然后在这行代码下面添加我在上面编写的警报函数。我想知道用户是要重新加载表单还是其他表单。此警报可防止表单的双重传输。