0

I want to change an image periodically in a UIImageView in my application, and the image will come from the web. Can I run JavaScript enabled pages in a UIWebView? Or are there any other ways to implement this?

2 Answers 2

1

I think JavaScript is the wrong approach. (You start off talking about a UIImageView - I guess that is where you want your image?) Use an NSTimer to update your image. You can easily fetch an image from a URL

http://blogs.oreilly.com/digitalmedia/2008/02/creating-an-uiimage-from-a-url.html

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

Comments

1

Edit: Oh, sorry, I missed that you wanted to place the image in a UIImageView. Andiihs answer will guide you better than mine. I will keep my answer for anyone stumbling into this looking for how to run JavaScript.

Just use stringByEvaluatingJavaScriptFromString: and you have executed the JavaScript on the loaded page in your UIWebView. This scripts reads the page title and places it in the "pageTitle" variable.

NSString *pageTitle = [myWebView stringByEvaluatingJavaScriptFromString:@"document.title"];

You can also perform any methods etc...

[myWebView stringByEvaluatingJavaScriptFromString:@"doSomething('Hello!'); doSomethingElse('And again...');"];

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.