1

I'm making an iOS app that gets content from a website. This website allows to vote for content through a JS script that is called when a link is clicked in the web page.

I would like to implement voting in my app without having to show the webpage to the user and asking im to click on vote.

I know it is possible to execute a javascript function of a UIWebView using

[myWebView stringByEvaluatingJavaScriptFromString:@"myJSFunction()"]

But loading a UIWebView is a bit long, specially since it's just to vote (should be fast), isn't there an easier way to just call for the JS function without requiring user interarction (except taping the vote button in the app, of course)

Thanks !

3
  • How are you displaying the content that is retrieved from the website? I'm assuming its not a uiwebview since you are trying to avoid loading that. Are you responsible for the website side as well (specifically, the behavior of what the myJSFunction() does)? Commented May 30, 2012 at 14:08
  • Actually, i parse the content of the pages using my own HTML Parser and show them in a UITableView... No, actually i'm not responsible of the server side and the owner doesn't seem to be really okay with making a simple API to vote. I just know that there's this JS function and that it votes. I just know it uses Xajax to call PHP functions.. Commented May 30, 2012 at 14:13
  • stringByEvaluatingJavaScriptFromString is the only way to execute JS on iOS (excluding Safari of course). Commented May 30, 2012 at 19:39

1 Answer 1

1

On iOS that function is the only way to execute a JS function.

Are you talking about using a native UI to enter some vote info, but processing the info gets done by the JS?

It depends upon what the JS is doing i.e. if its interacting with the dom etc., but you may not necessarily have to wait for the UIWebView to have finished downloading/loading/rendering the web page before you can call stringByEvaluatingJavaScriptFromString. The JS maybe ready to use immediatly in which case you can call stringByEvaluatingJavaScriptFromString before waiting for webViewDidFinishLoad gets called?

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

Comments

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.