开发者

Sending existing NSStrings to StringByEvaluatingJavaScriptFromString

开发者 https://www.devze.com 2023-01-24 08:41 出处:网络
Here\'s my Code: NSString *js =[NSString stringWithFormat:@\"document.getElementsByTagName(\'body\')[0].innerHTML = \'<h1>%@</h1>\';\",s];

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

精彩评论

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