Einzelnen Beitrag anzeigen

Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#7

AW: Klasse eines <body>-Tag im Webbrowser ändern

  Alt 5. Apr 2018, 11:51
So hat es bei mir funktioniert:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  E: IHTMLElement;
begin
  E := (Webbrowser1.Document AS IHTMLDocument2).body;
  if E <> NIL then
    E.setAttribute('className', 'light', 2); // Weiß nicht obs für die 2 ne schöne Konstante gibt
end;
Hab das HTML leicht abgeändert weil ich keine extra CSS Dateien haben wollte:
Code:
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Test</title>
    <style>
      body {
        border: none;
        margin: 0;
        padding: 0;
      }
     .dark {
        background-color:black;
        color:white;
     }
     .light {
        background-color:rgb(220,240,250);
     }
    </style>
  </head>

  <body class="dark">
      Test
  </body>
</html>
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."

Geändert von Neutral General ( 5. Apr 2018 um 11:53 Uhr)
  Mit Zitat antworten Zitat