RSS
TWebBrowserでCSSを一時的に無効化する

これを利用すると、スタイルシートを一時的に無効にしたり、有効にしなおしたりといった動作が行えます。HTMLがスタイルシート無効の環境でも満足か見れるかを検証するときに使うと便利な機能です。

まずusesにSHDocVw_TLB, MSHTML_TLBを追加し、以下の関数を定義してください。

procedure TForm1.DisableStyleStyleSheets(Disable: Boolean);
  procedure DisableStyle(Doc: IHTMLDocument2);
  var
    i: integer;
    ele: OLEVariant;
    w: OLEVariant;
  begin
    for i := 0 to Doc.styleSheets.length-1 do
    begin
      w := i;
      ele := Doc.styleSheets.item(w);
      try
        ele.disabled := Disable;
      except
      end;
    end;
  end;
var
  HTML: IHTMLDocument2;
  FRHTML: IHTMLWindow2;
  Fr: IDispatch;
  i: integer;
  index: OleVariant;
begin
  if WebBrowser1.Document = nil then
    Exit;
  try
    HTML := WebBrowser1.Document as IHTMLDocument2;
    DisableStyle(HTML);
  except
  end;

  if HTML.frames.length <> 0 then
  begin
    for i := HTML.frames.length - 1 downto 0 do
    begin
      index := i;
      Fr := HTML.frames.item(index);
      if Assigned(Fr) then
      begin
        FRHTML := Fr as IHTMLWindow2;
        if Assigned(FRHTML) then
        begin
          try
            HTML := FRHTML.document as IHTMLDocument2;
            DisableStyle(HTML);
          except
          end;
        end;
      end;
    end;
  end;
end;

使い方としては、DisableにTrueを渡すとスタイルシートを無効に、Falseを渡すと無効にしたスタイルシートを再度有効にします。