Created
October 26, 2015 11:26
-
-
Save eralpkaraduman/1e4e860e9a1875f27d62 to your computer and use it in GitHub Desktop.
executing javascript on WKWebView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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