How to append additional text with existing html content in android?

后端 未结 1 818
死守一世寂寞
死守一世寂寞 2021-01-07 12:56

I am Developing an application.In which i am appending a text to existing text which is stored in .html file, the location for the .html file is in my application\'s \"asset

1条回答
  •  天涯浪人
    2021-01-07 13:41

    Appending to HTML (concatenation) as String joining is not a good solution, but you can try this approach which will ensure that the html document's sanctity is not broken. Since you have the HTML document with you, it signifies you have control over that document and hence you should be able to do this which I am mentioning below.

    1) Create a function in HTML

     function appendText(extraStr) {
         document.getElementsByTagName('body')[0].innerHTML =     document.getElementsByTagName('body')[0].innerHTML + extraStr;
     }  
    

    2) On WebView load call this function

     myWebView.loadUrl("javascript:appendText('extra text or html here')"); 
    

    3) Don't forget to add this

     myWebView.getSettings().setJavaScriptEnabled(true);
    

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题