0

I am new to iOS here, so please don't mind if the question sounds silly. I am making an iPad app, and want to include a web page using the UIWebView. Took care of that. Now I want active transmission of data, comunication between the web page and native. I have been passing data from web page to iOS by making a dummy URL and using webView:shouldStartLoadWithRequest:navigationType: method. I understand and tested stringByEvaluatingJavaScriptFromString: can be used to invoke a JS function inside the webView. I had 2 question on that side -
1) is there any other way besides stringByEvaluatingJavaScriptFromString: to invoke a functionality on webView?
2) from my initial finding, I can only call a JS function which is in the source of this webView. Can I fire another function which may be in a separate JS file included in the source of webpage?

1 Answer 1

1

So first off, "from my initial finding, I can only call a JS function which is in the source of this webView. Can I fire another function which may be in a separate JS file included in the source of webpage?"

My understanding of JS is that if a separate file is in the source, then it is already in the source of the webView? Or is there some scenario where this is not the case?

Also, I do not think there is a way to avoid stringByEvaluating... but check this repo out, it is very popular:

https://github.com/marcuswestin/WebViewJavascriptBridge

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

1 Comment

"My understanding of JS is that if a separate file is in the source, then it is already in the source of the webView? Or is there some scenario where this is not the case?" This is, sort of part of my question. If there is a function fully defined in a separate file, I can't see that function when I do a view source can I? I don't suppose I can. And if I can't, can stringByEvaluatingJavaScriptFromString: "see" can function body and execute it?

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.