开发者

Sending existing NSStrings to StringByEvaluatingJavaScriptFromString

Here's my Code:

NSString *js =[NSString stringWithFormat:@"document.getElementsByTagName('body')[0].innerHTML = '<h1>%@</h1>';",s];
[pageView stringByEvaluatingJavaScriptFromString:js];

pageView is a UIWebView already loaded with an html document. I want it to show the NSString s. However, when this function is called, the vi开发者_StackOverflow社区sible html stays the same. I know s has a value because it is printing properly to the console one line above this. If I replace "%@" with say, "poot", "poot" appears in the h1 tag of the html as it should.

Shouldn't I be able to send s to the html like this?

Thanks.


What is the expected content of s? If it makes your JavaScript syntactically invalid, that could cause this problem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜