I am loading a webpage using UIWebView
let urlStr = "http://duckduckgo.com" let urlReq = NSMutableURLRequest(URL: NSURL(string: urlStr)!) webView.loadRequest(urlReq)
Then, when the page has finished loading, I want to access the html content
func webViewDidFinishLoad(webView: UIWebView) { let href = webView.stringByEvaluatingJavaScriptFromString("window.location.href") println("window.location.href = \(href)") let doc = webView.stringByEvaluatingJavaScriptFromString("document") println("document = \(doc)") }
But the document just returns an empty string ( Optional("") ). The window.location.href part is working fine. What am I doing wrong?
source share