开发者

Is JavaScript runnable in UIWebView?

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?


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


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...');"];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜