Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Modifying HTML-source before displaying it in the browser

Modifying HTML-source before displaying it in the browser

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi I hope someone of you is able to solve my problem. What I want to do is to write a plugin for the InternetExplorer (a so called BHO - Browser Helper Object) that will modify the HTML content before InternetExplorer displays the webpage. I already wrote a plugin which will catch the DWebBrowserEvents2::DocumentComplete event. This is my code which works so far:

    HRESULT __stdcall CCounter::DocumentComplete(IDispatch* pDisp, VARIANT * URL )
    {
    ATLTRACE(_T("CCounter::DocumentComplete\n"));

        return S\_OK;
    

    }

    What I now want to do is a bit complicated: Before the browser is about to display the webpage I want to get access and to the document's content and modify it (e.g. for removing keywords previously defined in an external file) I hope someone of you can help me, since it is a question which can't be explained in 1 minute. Thanks in advance regards Gregor

    M 1 Reply Last reply
    0
    • L Lost User

      Hi I hope someone of you is able to solve my problem. What I want to do is to write a plugin for the InternetExplorer (a so called BHO - Browser Helper Object) that will modify the HTML content before InternetExplorer displays the webpage. I already wrote a plugin which will catch the DWebBrowserEvents2::DocumentComplete event. This is my code which works so far:

      HRESULT __stdcall CCounter::DocumentComplete(IDispatch* pDisp, VARIANT * URL )
      {
      ATLTRACE(_T("CCounter::DocumentComplete\n"));

          return S\_OK;
      

      }

      What I now want to do is a bit complicated: Before the browser is about to display the webpage I want to get access and to the document's content and modify it (e.g. for removing keywords previously defined in an external file) I hope someone of you can help me, since it is a question which can't be explained in 1 minute. Thanks in advance regards Gregor

      M Offline
      M Offline
      moliate
      wrote on last edited by
      #2

      When the DocumentComplete event is sent, a great deal of rendering is already done. This will not prevent you from modifing the document "on the fly". What I would suggest is the following: 1) QueryInterface pDisp for the IWebBrowser2 interface (or call Invoke directly) 2) Use IWebBrowser2::get_Document to get a pointer to the (Dispinterface of; QueryInterface again) IHTMLDocument2. If the document contains frames you have to find the interface for each frame, and repeat step 3 for each of them. 3) Get the body element and send it to an recursive function that handles each leaf element (gets/puts outer text). It then finds all element children and feed them back to the function. This is just an suggestion, and perhaps someone has a better solution. Sorry if I don´t go into all technical details, but I hope this will help a little. /moliate

      L 1 Reply Last reply
      0
      • M moliate

        When the DocumentComplete event is sent, a great deal of rendering is already done. This will not prevent you from modifing the document "on the fly". What I would suggest is the following: 1) QueryInterface pDisp for the IWebBrowser2 interface (or call Invoke directly) 2) Use IWebBrowser2::get_Document to get a pointer to the (Dispinterface of; QueryInterface again) IHTMLDocument2. If the document contains frames you have to find the interface for each frame, and repeat step 3 for each of them. 3) Get the body element and send it to an recursive function that handles each leaf element (gets/puts outer text). It then finds all element children and feed them back to the function. This is just an suggestion, and perhaps someone has a better solution. Sorry if I don´t go into all technical details, but I hope this will help a little. /moliate

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        As I recall from my prevous experience on close to that issue: DocumentComplete Event may not be always fired... So, check Refresh for example... I recall it didn't work for me... But again, it could be previous versions of WebBrowser... Everything else as rightly described in previous message... GL Igor

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups