I'm trying to create an element with a image to a windows forms webbrowser control existing site. Then I want to move the created element to a certain position. I have this code, but it doesn't work.
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.GetElementById("gpu_notice").Style = "display:none";
webBrowser1.Document.GetElementById("header").OuterHtml = "";
webBrowser1.Document.GetElementById("ads").OuterHtml = "";
webBrowser1.Document.GetElementById("the_game").Style += "position: absolute; top: 0px; right: 0px;";
HtmlElement logo = webBrowser1.Document.CreateElement("logo");
logo.SetAttribute("SRC", @"C:\Users\Susana\Documents\Projeto HaxballK\Design\Logo HK.png");
webBrowser1.Document.Body.AppendChild(logo);
logo.SetAttribute("float", "right");
}
Is the task inserting an element to an existing HTML document displayed with the
WebBrowser
class? If yes, then the steps could be (not tested, sorry)WebClient
as a HTML string<body>
relative in the HTML string (insertstyle='position: relative'
into the<body>
element)<body>
, make the element absolute (settingstyle='position: absolute; left=...; right=...'
DocumentText
property of theWebBrowser
classYou have to use "img" tag instead of "logo" and set the file path with using file protocol.
UPDATED
If you want to add the image after all the JavaScript initializations have run, simply use one off
Timer
.