WebBrowser - changing HTML content after DocumentCompleted event

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robson Siqueira

    WebBrowser - changing HTML content after DocumentCompleted event

    Folks,

    I am facing a problem. I am trying to manipulate the HTML data (thru the
    Document and DocumentText properties) of the WebBrowser object
    (System.Windows .Forms).

    The problem is that the application enters in a loop state and my changes
    don't apply.

    Have somebody faced the same problem? Any solutions?

    I am using C# / .Net 2.0.

    --
    Regards,
    Robson Siqueira
    Enterprise Architect


  • Ben Rush

    #2
    Re: WebBrowser - changing HTML content after DocumentComplet ed event

    Hi.

    I've done a lot of code that resuses the IE control. I'm not sure what you
    mean by "the application enters in a loop state", though. You mean your code
    goes into a tight loop and the app freezes or what? If so, don't do that...
    :-)

    Can you give me an example of exactly what you're trying to change/do?
    Perhaps something I can recreate on my end/write a quick piece of code as an
    example for you?

    --
    ~~~~~~~~~~~
    Ben Rush



    "Robson Siqueira" <robson@robsonf elix.comwrote in message
    news:u3DFjbocHH A.1312@TK2MSFTN GP06.phx.gbl...
    Folks,
    >
    I am facing a problem. I am trying to manipulate the HTML data (thru the
    Document and DocumentText properties) of the WebBrowser object
    (System.Windows .Forms).
    >
    The problem is that the application enters in a loop state and my changes
    don't apply.
    >
    Have somebody faced the same problem? Any solutions?
    >
    I am using C# / .Net 2.0.
    >
    --
    Regards,
    Robson Siqueira
    Enterprise Architect
    >

    Comment

    • Robson Siqueira

      #3
      Re: WebBrowser - changing HTML content after DocumentComplet ed event

      Actually I want to change the code after it is loaded, which happens after
      the DocumentComplet ed Event. The problem is that the application keeps
      loading the file - if you change it goes all the way over again - and so on.

      Do you have any example in which you manipulate the HTML code AFTER the
      document was loaded?

      Thanks!

      --
      Regards,
      Robson Siqueira
      Enterprise Architect
      "Ben Rush" <kwendex@yahoo. comwrote in message
      news:%23KGip7pc HHA.1240@TK2MSF TNGP04.phx.gbl. ..
      Hi.
      >
      I've done a lot of code that resuses the IE control. I'm not sure what you
      mean by "the application enters in a loop state", though. You mean your
      code goes into a tight loop and the app freezes or what? If so, don't do
      that... :-)
      >
      Can you give me an example of exactly what you're trying to change/do?
      Perhaps something I can recreate on my end/write a quick piece of code as
      an example for you?
      >
      --
      ~~~~~~~~~~~
      Ben Rush

      >
      >
      "Robson Siqueira" <robson@robsonf elix.comwrote in message
      news:u3DFjbocHH A.1312@TK2MSFTN GP06.phx.gbl...
      >Folks,
      >>
      >I am facing a problem. I am trying to manipulate the HTML data (thru the
      >Document and DocumentText properties) of the WebBrowser object
      >(System.Window s.Forms).
      >>
      >The problem is that the application enters in a loop state and my changes
      >don't apply.
      >>
      >Have somebody faced the same problem? Any solutions?
      >>
      >I am using C# / .Net 2.0.
      >>
      >--
      >Regards,
      >Robson Siqueira
      >Enterprise Architect
      >>
      >
      >

      Comment

      • Jon Davis

        #4
        Re: WebBrowser - changing HTML content after DocumentComplet ed event

        Sounds like you might be having the same problem I had.

        Click on this:
        news://msnews.microsoft.com/eeUDRpxc...TNGP02.phx.gbl

        If your problem is similar to mine, then to get the DocumentComplet e when it
        loads, reference shdocvw (find the COM object DLL in
        C:\Windows\Syst em32\shdocvw.dl l and reference it in your .NET app) and cast
        your ((System.Window s.Forms.WebBrow ser)webBrowser1 ).ActiveXObject to a
        SHDocVw.WebBrow ser variable. Then subscribe to the DocumentComplet e event of
        the COM object, rather than the DocumentComplet e event of the Windows Forms
        instance.

        shdocvw.WebBrow ser _ActiveXBrowser = null;
        public shdocvw.WebBrow ser ActiveXBrowser
        {
        get
        {
        if (_ActiveXBrowse r == null)
        {
        _ActiveXBrowser =
        (SHDocVw.WebBro wser)myWebBrows er.ActiveXInsta nce;
        }
        return _ActiveXBrowser ;
        }
        }

        private void InitBrowser()
        {
        _ActiveXBrowser .DocumentComple te += new
        SHDocVw.DWebBro wserEvents2_Doc umentCompleteEv entHandler(Acti veXBrowser_Docu mentComplete);
        }


        To avoid the re-load loop after changing the document content, set a flag in
        your event handler to ignore the event if you just changed something.

        Jon


        "Robson Siqueira" <robson@robsonf elix.comwrote in message
        news:ellBozxcHH A.3408@TK2MSFTN GP03.phx.gbl...
        Actually I want to change the code after it is loaded, which happens after
        the DocumentComplet ed Event. The problem is that the application keeps
        loading the file - if you change it goes all the way over again - and so
        on.
        >
        Do you have any example in which you manipulate the HTML code AFTER the
        document was loaded?
        >
        Thanks!
        >
        --
        Regards,
        Robson Siqueira
        Enterprise Architect
        "Ben Rush" <kwendex@yahoo. comwrote in message
        news:%23KGip7pc HHA.1240@TK2MSF TNGP04.phx.gbl. ..
        >Hi.
        >>
        >I've done a lot of code that resuses the IE control. I'm not sure what
        >you mean by "the application enters in a loop state", though. You mean
        >your code goes into a tight loop and the app freezes or what? If so,
        >don't do that... :-)
        >>
        >Can you give me an example of exactly what you're trying to change/do?
        >Perhaps something I can recreate on my end/write a quick piece of code as
        >an example for you?
        >>
        >--
        >~~~~~~~~~~~
        >Ben Rush
        >http://www.ben-rush.net/blog
        >>
        >>
        >"Robson Siqueira" <robson@robsonf elix.comwrote in message
        >news:u3DFjbocH HA.1312@TK2MSFT NGP06.phx.gbl.. .
        >>Folks,
        >>>
        >>I am facing a problem. I am trying to manipulate the HTML data (thru the
        >>Document and DocumentText properties) of the WebBrowser object
        >>(System.Windo ws.Forms).
        >>>
        >>The problem is that the application enters in a loop state and my
        >>changes don't apply.
        >>>
        >>Have somebody faced the same problem? Any solutions?
        >>>
        >>I am using C# / .Net 2.0.
        >>>
        >>--
        >>Regards,
        >>Robson Siqueira
        >>Enterprise Architect
        >>>
        >>
        >>
        >
        >

        Comment

        • Jon Davis

          #5
          Re: WebBrowser - changing HTML content after DocumentComplet ed event

          Also if you're dynamicizing the content, try to use the IE-DHTML DOM first,
          i.e. myBrowser.Docum ent.Body.InnerH tml = ..., rather than
          myBrowser.Docum entText = .... Or, use
          ((mshtml.HTMLDo cument)myBrowse r.Document.DomD ocument).body.i nnerHTML=...
          (with mshtml.dll referenced).

          Jon


          "Robson Siqueira" <robson@robsonf elix.comwrote in message
          news:ellBozxcHH A.3408@TK2MSFTN GP03.phx.gbl...
          Actually I want to change the code after it is loaded, which happens after
          the DocumentComplet ed Event. The problem is that the application keeps
          loading the file - if you change it goes all the way over again - and so
          on.
          >
          Do you have any example in which you manipulate the HTML code AFTER the
          document was loaded?
          >
          Thanks!
          >
          --
          Regards,
          Robson Siqueira
          Enterprise Architect
          "Ben Rush" <kwendex@yahoo. comwrote in message
          news:%23KGip7pc HHA.1240@TK2MSF TNGP04.phx.gbl. ..
          >Hi.
          >>
          >I've done a lot of code that resuses the IE control. I'm not sure what
          >you mean by "the application enters in a loop state", though. You mean
          >your code goes into a tight loop and the app freezes or what? If so,
          >don't do that... :-)
          >>
          >Can you give me an example of exactly what you're trying to change/do?
          >Perhaps something I can recreate on my end/write a quick piece of code as
          >an example for you?
          >>
          >--
          >~~~~~~~~~~~
          >Ben Rush
          >http://www.ben-rush.net/blog
          >>
          >>
          >"Robson Siqueira" <robson@robsonf elix.comwrote in message
          >news:u3DFjbocH HA.1312@TK2MSFT NGP06.phx.gbl.. .
          >>Folks,
          >>>
          >>I am facing a problem. I am trying to manipulate the HTML data (thru the
          >>Document and DocumentText properties) of the WebBrowser object
          >>(System.Windo ws.Forms).
          >>>
          >>The problem is that the application enters in a loop state and my
          >>changes don't apply.
          >>>
          >>Have somebody faced the same problem? Any solutions?
          >>>
          >>I am using C# / .Net 2.0.
          >>>
          >>--
          >>Regards,
          >>Robson Siqueira
          >>Enterprise Architect
          >>>
          >>
          >>
          >
          >

          Comment

          Working...