Update Text Inside Page With Image

邮差的信 提交于 2020-01-15 11:08:10

问题


I am working with Delphi7 and TEmbeddedWB. I have some difficulty to update text of a page in twebbrowser. Because that webpage contains images. So Complete Html code is

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'#$D#$A'
<HTML>
    <HEAD>'#$D#$A'
        <META content="text/html; charset=windows-1252" http-equiv=Content-Type>'#$D#$A'
        <META name=GENERATOR content="MSHTML 8.00.7601.17514">
    </HEAD>'#$D#$A'
    <BODY>'#$D#$A'
       <DIV align=center><**IMG '#$D#$A'src="file:///C:/Program%20Files/image/c.jpg"></DIV>
       <FONT '#$D#$A'size=2 face=Arial><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">'#$D#$A'<P>**Hello «Forename», '#$D#$A'thiss<BR><BR><BR>«signature»<BR>**</P></SPAN></FONT>
    </BODY>
</HTML>'#$D#$A.

So I need to update only text like from (Hello «Forename» this «signature») to (this is a demo page). When I go to set Doc.Body.innerText := this is a demo page. Then On showing page image does remove, only text is display.

Please tell me how would be update text inside page with image. Please help me


回答1:


Maybe you can use the StringReplace function of Delphi to replace the text in the HTML of the browser, so something like:

Doc.Body.innerHTML := StringReplace(Doc.Body.innerHTML, '«signature»', 'Your Signature', []);

innerHTML should return the body contents, including all elements, while innerText only gets the text, without markup.

A nicer way would be to use methods like getElementById and other similar methods that you have available in e.g. Javascript, but I don't know if those methods are exposed by TEmbeddedWB.



来源:https://stackoverflow.com/questions/16960649/update-text-inside-page-with-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!