How to load a url link that is inside a web view and keep it in that web view in SWIFT

前端 未结 2 943
傲寒
傲寒 2020-12-22 10:03

I have a web view that has a webpage with links at the bottom. I have a way to deal with them being clicked, but all it does is open them into a new safari browser. This is

2条回答
  •  攒了一身酷
    2020-12-22 10:43

    Give delegates to your UIViewcontroller : UIWebViewDelegate

     let url = NSURL(string: "http://www.djmazacool.com")
     let req = NSURLRequest(URL: url!)
     YOURWEBVIEW.delegate = self
     YOURWEBVIEW.loadRequest(req)
    
    
    
    func webViewDidStartLoad(webView: UIWebView)
    {
            // start animation
            print("start loaded call")
    }
    func webViewDidFinishLoad(webView: UIWebView)
    {
            // load url complete
            print("loading done call")
    }
    

    Output :

    Don't Forgot to add this attribute in .plist file.

    NSAppTransportSecurity
    
        NSAllowsArbitraryLoads
        
    
    

提交回复
热议问题