开发者

How to edit html (tags), before being executed by CppWebBrowser

开发者 https://www.devze.com 2023-04-09 16:20 出处:网络
I can\'t solve my problem, and I hope somebody knows how... I have a component on my form TCppWebBrowser, and when I navigate to a URL, after the document was downloaded, in method OnDocumentComplete

I can't solve my problem, and I hope somebody knows how...

I have a component on my form TCppWebBrowser, and when I navigate to a URL, after the document was downloaded, in method OnDocumentComplete() , I'm trying to check and change html source of loaded document... before it being executed by browser.

I need that, because some websites have background sounds, and I want to parse html and remove tags or just remove text which contains sound files like *.wav , *.mid , *.swf, *.mp3 ... ect.

For example if html source have this line:

<NOEMBED><BGSOUND开发者_开发问答 src="/images/ImagineCut.wav"></NOEMBED>

then, i change it to:

<NOEMBED><BGSOUND src="/images/ImagineCut."></NOEMBED>

or I can delete whole tag.

Using this way I want to mute webbrowser or even to stop playing sounds. Please take into consideration this method, because it will help me to avoid all kind of sounds after I edited html.. (before browser execute it)

That's what I tried to do:

void __fastcall TForm1::CppWebBrowser1DocumentComplete(TObject *Sender,
      LPDISPATCH pDisp, Variant *URL)
{

IHTMLDocument2 *pHTMLDoc;
CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&pHTMLDoc);
IHTMLElement *pElem;
pHTMLDoc->get_body(&pElem);
BSTR text;
pElem->get_innerHTML(&text);
text = Cleaning(text); //checking and changing html without souds
pElem->put_innerHTML(text);
pElem->Release();
pHTMLDoc->Release();

}


To do what you are asking, you would have to download the HTML file yourself from outside of the TCppWebBrowser component completely, alter the HTML as needed, and then push the new HTML into TCppWebBrowser using one of its IPersist... interfaces. Examples of doing that have been posted in the Borland/CodeGear/Embarcadero forums many times before.

0

精彩评论

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

关注公众号