CSS and TWebbrowser delphi

后端 未结 2 1312
栀梦
栀梦 2021-01-07 03:08

I was wondering if it was possible to manipulate the CSS of websites. For example color in the input fields? I had a look at several questions, but its not clear to me if it

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-07 03:38

    It is possible to modify CSS by adding a stylesheet from code, after the page is loaded:

    var
       document: IHTMLDocument2;
       stylesheet: IHTMLStyleSheet;
       stylesheetIndex: Integer;
    begin
    
       // Inject CSS Style Sheets
       document := webBrowser1.Document as IHTMLDocument2;
    
       stylesheetIndex := document.styleSheets.length;
       if stylesheetIndex > 31 then
          raise Exception.Create('Already have the maximum amount of CSS stylesheets');
    
       stylesheet := document.createStyleSheet('', stylesheetIndex);
       stylesheet.cssText := ...
    
    

提交回复
热议问题