Modifying inbound HTML
-
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
-
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
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
-
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
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
-
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
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!
-
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!
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
-
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
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
-
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
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