WKWebView Swift javascript enable

Im trying to develop a simple app to browse my website. However my website contains some javascript and it doesn't successfully show my website.

In the past develop with android the same app and had to activate like this:


webSettings.setJavaScriptEnabled(true);

This currently my code I just have missing the option to enable javascript if somebody can help will really appreciate


import WebKit class ViewController: UIViewController {

@IBOutlet weak var webView: WKWebView!


override func viewDidLoad() {

super.viewDidLoad() let url = URL(string: "http://132.148.136.31:8082")

let urlRequest = URLRequest(url: url!)

webView.load(urlRequest)

}


}



I will really appreciate your help guys been struggling so much.

WKWebView always has JavaScript enabled, so that’s unlikely to be the problem. I recommend that you verify this by loading some common public web site in your web view.

As to what’s going wrong with your web site, it’s hard to be sure. The first thing to do is implement a navigation delegate and see if you get an error reported. Specifically:

  1. In

    viewDidLoad()
    , set
    self.webView.navigationDelegate
    to
    self
  2. Change

    ViewController
    to conform to
    WKNavigationDelegate
  3. In

    ViewController
    , implement the ‘did fail’ methods to log an error, for example:
    func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
        NSLog("did fail provisional navigation %@", error as NSError)
    }
    
    
    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
        NSLog("did fail navigation %@", error as NSError)
    }

    .

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
WKWebView Swift javascript enable
 
 
Q