Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: snakeboy8 en 29 Enero 2015, 01:21 am



Título: como agregar texto en el body de un webbrowser
Publicado por: snakeboy8 en 29 Enero 2015, 01:21 am
hola estoy tratando de agregar texto en un webbrowser con esto
Código
  1. WebBrowser1.Document.GetElementById("B").InnerText = "halo"

y este es el html

Código
  1. <body id="B" style="padding: 0px; margin: 2px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; background: rgb(255, 255, 255);>halo</body>

en el codigo html donde dice halo asi es como tendria que quedar pero no me funciona por que no agrega el texto alguien sabe como solucionar esto? :huh:


Título: Re: como agregar texto en el body de un webbrowser
Publicado por: Eleкtro en 29 Enero 2015, 02:20 am
¿Te has dado cuenta que en el html que has mostrado NO has encerrado el style de CSS con comillas dobles?, no se si ha sido un error de edición por tu parte al publicar el código, o si ese es el mismo html original de la página, entonces esa podría ser la causa del problema, ya que con este error de sintaxis yo tampoco consigo reconocer correctamente el elemento:
Citar
Código:
...255);>halo...

Ejemplo funcional:

Código
  1.    Private Sub HtmlTest()
  2.  
  3.        Dim htmlText As String =
  4. <a><![CDATA[
  5.    <body id="B"
  6.          style="padding: 0px;
  7.                 margin: 2px;
  8.                 color: rgb(0, 0, 0);
  9.                 font-family: Verdana, Arial, Helvetica, sans-serif;
  10.                 font-size: 15px;
  11.                 background: rgb(255, 255, 255);">
  12.  
  13.        This is a test inner text
  14.  
  15.    </body>
  16. ]]></a>.Value
  17.  
  18.        Dim htmlElement As HtmlElement
  19.  
  20.        Dim wb As New WebBrowser With
  21.            {
  22.                .Dock = DockStyle.Fill,
  23.                .DocumentText = String.Empty
  24.            }
  25.  
  26.        Me.Controls.Add(wb)
  27.  
  28.        wb.Document.Write(htmlText)
  29.        htmlElement = wb.Document.GetElementById("B")
  30.  
  31.        Select Case htmlElement Is Nothing
  32.  
  33.            Case False
  34.                htmlElement.InnerText = "halooooo???"
  35.                Debug.WriteLine(htmlElement.OuterHtml)
  36.  
  37.            Case Else
  38.                Throw New NullReferenceException("Element not found")
  39.  
  40.        End Select
  41.  
  42.    End Sub

Saludos


Título: Re: como agregar texto en el body de un webbrowser
Publicado por: snakeboy8 en 29 Enero 2015, 06:35 am
me funciono muy bien el codigo amigo gracias   :)