views:

108

answers:

1

I use Delphi 2010 . I am using twebbrowser to load up HTML source and view it. Now I want to click on an area (background, links, etc) in the web browser and get the styling in the CSS file that styles the HTML.

For example: I click on the H3 region and I want to be taken to the h3{ color: white; } in the CSS. Any help at all is much appreciated; this is hard for me to figure out.

A: 

You will have to handle the parsing of the source yourself to make this work. Because the CSS entry can be in another file or even files, this can be tricky. I would start by looking at the DIHtmlParser component which can help greatly here. You will have to parse the main document, and each identified CSS file to locate the proper file/position to jump too. I would also look at tEmbeddedWB as an alternative over TWebBrowser as it supplies much more control over the embedded browser as well as TRichEditWB which works well for viewing syntax highlighted HTML source.

Edit: You still have to parse the CSS and HTML to build an index of each tag and its CSS location. When your editing the HTML, you have to parse the tag your cursor is currently on or in, compare that to the index you parsed earlier, to display the CSS attributes in effect. Keep in mind that CSS cascades and nests, so your index will most likely be a tree, and your tag will be relative in that tree.

skamradt
Thanks for your comments.I have looked at DlHtmlParser, and I have tEmbeddedWB, and TRichEditWb.But I can not come up with a solution for what I am trying to do.
Grant
I am haveing the most trouble with finding out were you click (h3,Body,etc) in the twebbrowser. Does anyone know how to do this.Thanks
Grant