Skip to content

Instantly share code, notes, and snippets.

@eralpkaraduman
Created October 26, 2015 11:26
Show Gist options
  • Save eralpkaraduman/1e4e860e9a1875f27d62 to your computer and use it in GitHub Desktop.
Save eralpkaraduman/1e4e860e9a1875f27d62 to your computer and use it in GitHub Desktop.
executing javascript on WKWebView
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
let webView = WKWebView(frame: CGRectMake(0, 0, 1024, 720))
override func viewDidLoad() {
super.viewDidLoad()
webView.navigationDelegate = self
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
let req = NSURLRequest(URL: NSURL(string: "https://google.com")!)
webView.loadRequest(req)
}
func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {
let jsString = "document.title"
webView.evaluateJavaScript(jsString) { (result, error) -> Void in
print("result \(result)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment