UIWebview :: Text :: HTML :: JS
Posted
by user306089
on Stack Overflow
See other posts from Stack Overflow
or by user306089
Published on 2010-03-31T14:40:17Z
Indexed on
2010/03/31
14:43 UTC
Read the original article
Hit count: 167
iphone
hello,
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
© Stack Overflow or respective owner