1

I am showing a webView to my iOS app (Swift). From the webView I need to retrieve an object (javascript). Using the console I can see that the object I want is called "window.user" but using the following method is returning no results. Is there a way ? Thank you.

if let result = self.webView.stringByEvaluatingJavaScript(from: "document.getElementById(‘window.user’)") {
         print(result)
 }

1 Answer 1

1
  1. You need to use WKWebView (not UIWebView)
  2. You need to inject JS code into your page. Which will return your Document property. When the return event is triggered, you can handle it with your Swift code.

Example

Call JavaScript function from native code in WKWebView

Sign up to request clarification or add additional context in comments.

1 Comment

Have you found a solution of your question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.