开发者

Dynamically replace HTML element in UIWebView

I have some HTML loaded in WebView like this:

<html><head></head><body>before  <myTag>Content</myTag>  after</body></html>

I want to replace element myTag with custom text so it sho开发者_StackOverflowuld look like:

 <html><head></head><body>before  ____MY_CUSTOM_TEXT___  after</body></html>

Also I can't change initial HTML. How I can do this with JavaScript?

My not finished code:

var elements = document.getElementsByTagName( 'myTag' );
var firstElement = elements[0];
var parentElement = firstElement.parentNode;
var html = parentElement.innerHTML;
parentElement.innerHTML = html.replace(?????, '____MY_CUSTOM_TEXT___');

I don't know how to get string value of element to replace (?????).


Here you go:

var txt = document.createTextNode('____MY_CUSTOM_TEXT___');
parentElement.replaceChild(txt, firstElement);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜