开发者

UIWebview :: Text :: HTML :: JS

开发者 https://www.devze.com 2022-12-25 01:22 出处:网络
1- i load a text开发者_运维知识库 from a txt file 2- i show it into a html \"file\" 3- problem :

1- i load a text开发者_运维知识库 from a txt file

2- i show it into a html "file" 3- problem :

3-a : this code works :

i create my page by code and i insert my text

myText = ... loaded from an array of texts ...;
 NSString *myDescriptionHTML = [NSString stringWithFormat:@"<html> \n"
 "<head> \n"
 "<style type=\"text/css\"> \n"
 "body {font-family: \"%@\"; font-size: 1.0f + 'em'; color:#FFF;}\n"
 "</style> \n"
 "</head> \n"
 "<body id=\"myid\">%@</body> \n"
 "</html>", @"Arial", myText];
 [self.myWebView loadHTMLString:myDescriptionHTML baseURL:nil];

3-b but this one does not work :

i load a html page already created and i inject my text into using JS :

myText = ... loaded from an array of texts ...;
 [self.myWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById(\"myid\").innerHTML = \"%@\";", myText]];

3-c but this one working :

same as 3-b but i init my text with a string in the code itself :

myText = @"hello all";
 [self.myWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById(\"myid\").innerHTML = \"%@\";", myText]];

any help to understand what's wrong with 3-b ?

thank you

0

精彩评论

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

关注公众号