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#
  4. Modifying inbound HTML

Modifying inbound HTML

Scheduled Pinned Locked Moved C#
csharpc++htmllinuxtutorial
7 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.
  • S Offline
    S Offline
    Sunil Shindekar
    wrote on last edited by
    #1

    Hi, I want to write a program which will modify the inbound HTML in the IE 6.0. It will capture the inbound HTML before it gets displayed, make some modifications in it and display it in the IE. Can anybody tell me how to achieve this? The typical flow will be - User will enter the URL in the Internet explorer Address Bar. The incoming HTML will be read by my program before it gets displayed. My program will modify some strings - say phone numbers in it and display the modified HTML. Technology is not a restriction. I am ready to use VC++ or .NET. Do I have to use shell Extension? If yes, which interface/event will be helpful? Thanks in advance. Regards, Sunil

    L 1 Reply Last reply
    0
    • S Sunil Shindekar

      Hi, I want to write a program which will modify the inbound HTML in the IE 6.0. It will capture the inbound HTML before it gets displayed, make some modifications in it and display it in the IE. Can anybody tell me how to achieve this? The typical flow will be - User will enter the URL in the Internet explorer Address Bar. The incoming HTML will be read by my program before it gets displayed. My program will modify some strings - say phone numbers in it and display the modified HTML. Technology is not a restriction. I am ready to use VC++ or .NET. Do I have to use shell Extension? If yes, which interface/event will be helpful? Thanks in advance. Regards, Sunil

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

      Hello! That's kinda easy to implement: Just capture the "DownloadComplete"-event, get the Document-property and then the outertext-property of the body... Change the values and write it back to the outertext-property: private void m_Browser_DownloadComplete(object sender, System.EventArgs e) { IHTMLDocument2 loDocument = (IHTMLDocument2)this.m_Browser.Document; string lsHtml = Document.body.outerHTML; // make changes Document.body.outerHTML = lsHtml; } In the above shown example, you can see that it just change the body. Another thing is, that you won't see it in the source-code when you open the source-file with the IE context menue. To change the whole file (and document)... you can write an HTML-file back with the write-methode of the browser component. Don't forget to clear the document object with the clear-methode, b4 you load a new one! I hope I could help you! Marcel Erz -- modified at 9:10 Monday 12th December, 2005

      S 2 Replies Last reply
      0
      • L Lost User

        Hello! That's kinda easy to implement: Just capture the "DownloadComplete"-event, get the Document-property and then the outertext-property of the body... Change the values and write it back to the outertext-property: private void m_Browser_DownloadComplete(object sender, System.EventArgs e) { IHTMLDocument2 loDocument = (IHTMLDocument2)this.m_Browser.Document; string lsHtml = Document.body.outerHTML; // make changes Document.body.outerHTML = lsHtml; } In the above shown example, you can see that it just change the body. Another thing is, that you won't see it in the source-code when you open the source-file with the IE context menue. To change the whole file (and document)... you can write an HTML-file back with the write-methode of the browser component. Don't forget to clear the document object with the clear-methode, b4 you load a new one! I hope I could help you! Marcel Erz -- modified at 9:10 Monday 12th December, 2005

        S Offline
        S Offline
        Sunil Shindekar
        wrote on last edited by
        #3

        Hi, I have some more doubts. As I am novice to all these things, please excuse me if I am talking some non sense. As per my understanding, above solution assumes that the IE control is embedded in the application. In my case, IE will be invoked from Desktop and I want to capture any HTML which is loaded in that the browser loaded from Desktop. The HTML also might not be mine. It can be loaded by giving any URL like www.google.com or www.msn.com etc. So do I have to get the instance of the Internet Explorer which is invoked from Desktop? If yes, how to get the instance of it? Thanks, Sunil

        L 1 Reply Last reply
        0
        • S Sunil Shindekar

          Hi, I have some more doubts. As I am novice to all these things, please excuse me if I am talking some non sense. As per my understanding, above solution assumes that the IE control is embedded in the application. In my case, IE will be invoked from Desktop and I want to capture any HTML which is loaded in that the browser loaded from Desktop. The HTML also might not be mine. It can be loaded by giving any URL like www.google.com or www.msn.com etc. So do I have to get the instance of the Internet Explorer which is invoked from Desktop? If yes, how to get the instance of it? Thanks, Sunil

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

          Hi! Here is an example to catch all running instances: public void FindIE() { // Retrieve list of all IE instances SHDocVw.ShellWindows loIEs = New SHDocVw.ShellWindows(); SHDocVw.InternetExplorer loIE = null; int llCount = 0; mshtml.IHTMLDocument2 loDocument = null; URLList.Items.Clear(); TitleList.Items.Clear(); IECountText.Text = loIEs.Count; while(llCount <= loIEs.Count) { loIE = loIEs.Item(llCount); llCount++; if (loIE != null) { URLList.Items.Add(loIE.LocationURL); loDocument = (mshtml.IHTMLDocument2)loIE.Document; if (loDocument != null) { TitleList.Items.Add(loDocument.title); } } } } URLList -> List of all URLs open from instaces TitleList -> List of all title tag data of all opened documents in the instances IECountText -> Amount of Instances found The "SHDocVw.ShellWindows" retrieve all instances of the IE. When every instance get created, it sign in to this list automatically, thats why you have an overview of all IE instances. "SHDocVw.InternetExplorer" is one instance of an IE. With this, you can kinda do everything what you can do with the browser inside your application. Here an example of changing html of all instances: public void ChangeAllIE() { // Retrieve list of all IE instances SHDocVw.ShellWindows loIEs = New SHDocVw.ShellWindows(); SHDocVw.InternetExplorer loIE = null; int llCount = 0; mshtml.IHTMLDocument2 loDocument = null; URLList.Items.Clear(); TitleList.Items.Clear(); IECountText.Text = loIEs.Count; while(llCount <= loIEs.Count) { loIE = loIEs.Item(llCount); llCount++; if (loIE != null) { URLList.Items.Add(loIE.LocationURL); loDocument = (mshtml.IHTMLDocument2)loIE.Document; if (loDocument != null) { loDocument.clear(); loDocument.writeln((object)"Changed html!"); loDocument.close(); } } } } I hope it is clear so far and it works like I said, coz cannot check it at the moment! I will try it tomorrow morning, but I think it will work! If you need more help, just post it here! Marcel Erz P.S.: Plz try to understand the code, and not just copy it. The best way to learn is, to read and understand code!

          S 1 Reply Last reply
          0
          • L Lost User

            Hi! Here is an example to catch all running instances: public void FindIE() { // Retrieve list of all IE instances SHDocVw.ShellWindows loIEs = New SHDocVw.ShellWindows(); SHDocVw.InternetExplorer loIE = null; int llCount = 0; mshtml.IHTMLDocument2 loDocument = null; URLList.Items.Clear(); TitleList.Items.Clear(); IECountText.Text = loIEs.Count; while(llCount <= loIEs.Count) { loIE = loIEs.Item(llCount); llCount++; if (loIE != null) { URLList.Items.Add(loIE.LocationURL); loDocument = (mshtml.IHTMLDocument2)loIE.Document; if (loDocument != null) { TitleList.Items.Add(loDocument.title); } } } } URLList -> List of all URLs open from instaces TitleList -> List of all title tag data of all opened documents in the instances IECountText -> Amount of Instances found The "SHDocVw.ShellWindows" retrieve all instances of the IE. When every instance get created, it sign in to this list automatically, thats why you have an overview of all IE instances. "SHDocVw.InternetExplorer" is one instance of an IE. With this, you can kinda do everything what you can do with the browser inside your application. Here an example of changing html of all instances: public void ChangeAllIE() { // Retrieve list of all IE instances SHDocVw.ShellWindows loIEs = New SHDocVw.ShellWindows(); SHDocVw.InternetExplorer loIE = null; int llCount = 0; mshtml.IHTMLDocument2 loDocument = null; URLList.Items.Clear(); TitleList.Items.Clear(); IECountText.Text = loIEs.Count; while(llCount <= loIEs.Count) { loIE = loIEs.Item(llCount); llCount++; if (loIE != null) { URLList.Items.Add(loIE.LocationURL); loDocument = (mshtml.IHTMLDocument2)loIE.Document; if (loDocument != null) { loDocument.clear(); loDocument.writeln((object)"Changed html!"); loDocument.close(); } } } } I hope it is clear so far and it works like I said, coz cannot check it at the moment! I will try it tomorrow morning, but I think it will work! If you need more help, just post it here! Marcel Erz P.S.: Plz try to understand the code, and not just copy it. The best way to learn is, to read and understand code!

            S Offline
            S Offline
            Sunil Shindekar
            wrote on last edited by
            #5

            Hi Marcel, Thank you for your reply and sample code. I have one more query. I want to create a toolbar for the Internet Explorer which will have controls like drop down and push buttons. I need to write the program in C#. Can you give me some direction in this regard? Thanks in advance. Sunil

            L 1 Reply Last reply
            0
            • S Sunil Shindekar

              Hi Marcel, Thank you for your reply and sample code. I have one more query. I want to create a toolbar for the Internet Explorer which will have controls like drop down and push buttons. I need to write the program in C#. Can you give me some direction in this regard? Thanks in advance. Sunil

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

              Hi! At the moment I don't really have a lot of time, but take a look at this: http://www.codeproject.com/csharp/dotnetbandobjects.asp[^] I think is that what you are looking for! Tell me if you have problems with it. May be I can help! Marcel Erz

              1 Reply Last reply
              0
              • L Lost User

                Hello! That's kinda easy to implement: Just capture the "DownloadComplete"-event, get the Document-property and then the outertext-property of the body... Change the values and write it back to the outertext-property: private void m_Browser_DownloadComplete(object sender, System.EventArgs e) { IHTMLDocument2 loDocument = (IHTMLDocument2)this.m_Browser.Document; string lsHtml = Document.body.outerHTML; // make changes Document.body.outerHTML = lsHtml; } In the above shown example, you can see that it just change the body. Another thing is, that you won't see it in the source-code when you open the source-file with the IE context menue. To change the whole file (and document)... you can write an HTML-file back with the write-methode of the browser component. Don't forget to clear the document object with the clear-methode, b4 you load a new one! I hope I could help you! Marcel Erz -- modified at 9:10 Monday 12th December, 2005

                S Offline
                S Offline
                Sunil Shindekar
                wrote on last edited by
                #7

                Hi, I wrote the program as mentioned above. However I used the event DocumentComplete instead of DownloadComplete. It is working fine if new URL is given in the browser window. But if Refresh button of browser is clicked, then DocumentComplete event is not getting fired. However DownloadComplete event is getting fired. But DownloadComplete event does not give me the WebBrowser object for which the event is fired as it is available in the DocumentComplete event. Is there any way in this function to get the instance of WebBrowser from which this event is fired? Thanks in advance. Regards, Sunil

                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