UIWebView delegate method shouldStartLoadWithRequest: equivalent in WKWebView?

前端 未结 7 925
忘掉有多难
忘掉有多难 2020-12-12 14:37

I have a module inside my iOS 7+ app which is a UIWebView. The html page loads a javascript that creates custom-shaped buttons (using the Raphaeljs library). With UIWebView,

7条回答
  •  暖寄归人
    2020-12-12 15:12

    In Swift you can do something like this:

    func webView(webView: WKWebView, decidePolicyForNavigationAction navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -> Void) {
    
        switch navigationAction.request.URLString {
        case "http://action.is.needed/some-action":
            self.someFunc()
            decisionHandler(.Cancel)
            break
        default:
            decisionHandler(.Allow)
            break
        }
    
    }
    

    And this is the link in web page:

    Hello world!
    

提交回复
热议问题