I'm facing an issue while trying to display the W3Schools website within an iOS Swift app using WKWebView. The website loads successfully, but when I attempt to interact with elements like the "Try it Yourself" button, nothing happens.
I've ensured that JavaScript is enabled, and I've set the can-open-windows-automatically property in the storyboard. Below is the relevant code snippet from my ViewController:
import UIKit
import WebKit
class ViewController: UIViewController,WKUIDelegate, WKNavigationDelegate {
@IBOutlet weak var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
self.setup()
webView.navigationDelegate = self
webView.load(NSURLRequest(url: NSURL(string: "https://www.w3schools.com/tags/att_a_target.asp")! as URL) as URLRequest)
}
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
if navigationAction.targetFrame == nil {
webView.load(navigationAction.request)
}
return nil
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
print("Page Finished Loading")
}
}