1

I have a file called proof.html like this one:

    <title>{title}</title>
    <link rel="stylesheet" type="text/css" href="{cssURL}" />
    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
</head>
<body class="{language} {custom}">
<div class="FeedTitle">{feedTitle}<br /><span><em>via</em> RSS</span></div>
<div class="Published">{date}</div>
<div class="Title"><a href="{sourceURL}">{title}</a></div>
<div class="Author">{author}</div>
<div class="RSS">{text}</div>
<div class="Original"><a href="{sourceURL}"></a></div>

Later on I am loading it in my UIWebViev using the command below:

 [doc loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"proof" ofType:@"html"]isDirectory:NO]]];

Now I can't understand how I can replace for example {author} with the real name of the autor of my news... How can I pass It to my UIWebView? Can someone share an example? Thanks.

2 Answers 2

3

You will need to use JavaScript to do this, with the method stringByEvaluatingJavaScriptFromString:

for example:

[yourWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById('Author').innerHTML = '%@';",authorsName]];

note: for the above example, you will need to add an id attribute to your divs.

Sign up to request clarification or add additional context in comments.

2 Comments

mmm I try your code but I can't understand how it works. NSString *author=@"Sample"; [doc stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById('author').innerHTML = '%@';",author]]; but I'll not able to replace {author] with the "Sample" string.
the document.getElementById('author') will search for the div element in your web page which has an idattribute equal to author. You must change you HTML to <div id="author" class="Author">{author}</div> for it to work
0

You can change it using javascript.

[webview stringByEvaluatingJavaScriptFromString:@"your js code"];

Above code will evaluate the javascript into ur current page. You can add js code to set the author to ur desired string.

1 Comment

Thanks I understand but I don't know I can create a funct that can replaced the {author} that I see on my uiwebview. Can you show mw an example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.