Is JavaScript runnable in UIWebView?

Question!

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?



Answers

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...');"];
By : alleus


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

By : Andiih


This video can help you solving your question :)
By: admin