Click here to Skip to main content
Click here to Skip to main content

Extended web browser control for .NET 1.0/1.1

By , 12 Dec 2004
 

Sample Image - WebBrowserEx.jpg

Quickstart

Pretty simple: download the project, run it. See 'Adding the referenced ActiveX controls' if it doesn't compile from reference issues.

Introduction

The next version of the .NET framework features a comprehensive wrapper class for the Microsoft Web Browser control - a COM control that is used by IE and is embedded into Explorer. This new control features everything people are at pains to produce using COM without fishing through newsgroups and tech articles.

Well, I thought it was about time there was an equivalent control for .NET 1.0 / .NET 1.1, so I've put my open-source apron on once more, to produce this control.

This control contains the following features that you do not get (without doing it yourself) with the standard AxWebBrowser control:

  • Context menu
  • Optionally opening all links in a new window
  • Show the find dialog
  • Show the print dialog
  • Show the save-as dialog
  • Show the print preview dialog
  • Disabling accelerator keys such as CTRL+N, CTRL+F and Backspace
  • Restrict images, Java, ActiveX
  • Stop images, sounds, videos from displaying
  • Disable JavaScript
  • Disable downloading/running of ActiveX and Java controls
  • Ability to turn a 3D border on or off
  • Turn the scrollbars on or off
  • Make all form controls XP themed
  • Simplified and more feature-rich navigation methods (Navigate with more options, Refresh with different refresh options.)
  • Documentation for the events.

In some ways, it's actually more feature-rich than the .NET 2.0 control, although the .NET 2.0 control features a security model implementation and a few other properties that will hopefully be put into WebBrowserEx during its lifetime.

How is it implemented?

I'm not going to bother going into detail about how it's been implemented - there is a wealth of information out there on the net that explains this already. See the References section for links to the places I got the information from. The control is a user control with the AxWebBrowser docked to full on it. I tried to derive from AxWebBrowser, but it didn't like me adding properties in, so I gave up on that method. This meant that in the control, lots of properties and events have had to be re-implemented. This was pretty boring to do, but has actually made for a more concise control than having a derived class with all its ActiveX properties drooping out.

IDocHostUIHandler and context menus

The control implements IDocHostUIHandler (see the References for what this is) which handles the context menu and key restrictions. Unlike the .NET 2.0 control, I've left the control with just a ContextMenu property. You can set this to a blank ContextMenu, e.g.:

myBrowser.ContextMenu = new ContextMenu();

if you don't want the default IE context menu. In the version 2 control, there is an additional option to not show the the IE context menu. If there's enough demand for this, I'll add it in.

The legend of the IDispatch_Invoke_Handler

The control also implements IOleClientSite. As before, you can read what this is in the References. The most obscure and important part of the control is the IDispatch_Invoke_Handler(). I spent quite a while trying to work out how to implement IDispatch::Invoke in order to restrict what IE was showing (such as images, ActiveX controls, Java). I found out that if you add a IDispatch_Invoke_Handler() method in your code with the COM dispatch identifier of -5512, this does the job for you. A very obscure answer, but it works well. The options enumeration then works with this to set the options you want available in your browser.

I don't believe the .NET 2.0 control has these options available; hopefully someone at MS who has ties to .NET will read this and request that it's added in, as they're quite core features for the control.

WebExecWB

The control features an easier to use ExecWB method which queries the interface before executing it, fixing the "Trying to revoke a drop target that has not been registered." and similar errors. The print, save-as etc. methods, use this wrapped call. You'll find, some of the CMDID constants do nothing. Welcome to the world of COM interop - I found out whilst making this control that some of the constants Microsoft has on the MSDN site haven't worked for years, and they just haven't bothered updating their documentation. Some of these constants may be useable by casting the CurrentDocument to an IOleCommandTarget, and calling its Exec method (see the Find method). This is basically all that the ExecWB method does anyway, as far as I'm aware.

Flags designer

The control implements Thierry Bouquain's designer flag editor for setting the options flags in the designer. It currently has all of its COM imports, interfaces and the flag designer editor in the single file. This makes the source a bit bulkier, but nothing that regions don't overcome. It also makes the control more self-contained in my view.

XP Service Pack 2

In XP Service pack 2, Microsoft has updated the MSHTML part of the browser so that you get more options in your NewWindow event (it's called NewWindowEvent3). I added this originally, but then realized that it would break on most people's machines due to dependency failures. You can add it quite easily to the control, if you want to know how your new window was created.

Adding the referenced ActiveX controls

When you download the project, you might find the following references missing:

  • AxInterop.SHDocVw.dll
  • Interop.SHDocVw.dll
  • Microsoft.mshtml.dll

I haven't included these as they are operating system dependent. I'm running XP SP2, whilst you might be running Windows 2000, XP SP1 etc., so my DLLs will break with your operating system, if I included them.

To add Microsoft.mshtml.dll is straight forward; click on the Add Reference in the project, and add the following:

Add the mshtml reference

Adding SHDocVw is slightly strange. As far as I know, you can't add it as reference, so you have to add it into your toolbox and add it to the control's form, then remove it (something to do with the AxImp tool and VS.NET, I'm not sure what). To do this, open up the WebBrowserEx control so it's in designer mode, and then go to your toolbox, click on Add/Remove items in the context menu, and select the following from the COM tab:

Adding the SHDocVw reference

Once that's added to your toolbox, add a temporary form to the WebBrowserEx project, drop it onto the form, and then remove it. This should add it to your references. Now, do a voodoo dance and compile, and hopefully all should be well.

I haven't tried compiling without VS.NET, adding the references should be straight forward enough though, using the AxImp tool with SHDocVw.dll.

DOM event handling

I've added support into the control for the MSHTML document events. The events allow you to capture keydown, mouseclick etc. events in the document - events which are not available to the browser control itself as it is just a host for the document parser. The implementation I've added is fairly experimental, and can be switched on using EnableHtmlDocumentHandling property. Setting this to true will mean all HtmlDocument* events are fired, however I should stress that these events tend to swallow up your key and mouse events and seem to make the form key presses and link clicking go screwy. I didn't have time to work out why this was, I'll probably have a look at it on a rainy Sunday.

And finally

The method and property names in the control don't match those of the .NET 2.0 control. Some are the same, some aren't. I can't really see a scenario where you'd upgrade from this to the new .NET 2.0 control, but if this is a big problem with people, I can change it so that all the property names and methods are the same.

One small touch I've added to the control is to include the documentation from MSDN for all of the events that come from AxWebBrowser.

That's all. I hope the control comes in useful.

References

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

yetanotherchris
Web Developer
United Kingdom United Kingdom
Member
London based C# programmer.
 
I maintain my own pet C# site http://www.sloppycode.net in my spare time.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
General安装自己写的程序时候弹出未能注册模块 D:\\VAFF\ieframe HRESULT-2147467263memberFFEE9926 May '11 - 21:10 
安装自己写的程序时候弹出未能注册模块 D:\\VAFF\ieframe HRESULT-2147467263
应该怎样修改
General为什么设置了我自己写的浏览器(IE核心)为默认浏览器,但是qq空间时弹出的是IE?memberFFEE9926 May '11 - 0:38 
这是我的设置默认浏览器代码
RegistryKey reg = Registry.ClassesRoot.CreateSubKey(@"http\shell\open\command");
reg.SetValue("", @"D:\wanmeirnet\wanmeirnet.exe");
怎样解决这个问题
QuestionLicensing questionmemberMichellle3 May '10 - 16:26 
Can I use this code in a commercial project that will be distributed to customers? I'll leave all copyright notices in place.
 
Thanks
QuestionHow to disable IE Script error?memberLehoanq13 Sep '09 - 17:01 
Hi, my page loaded by your app has an IE script error:
 
Error: Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus.
 
How can I make it silent? Or try/catch it? Thanks so much.
AnswerRe: How to disable IE Script error?memberCptHook28 Jan '11 - 0:26 
webBrowser.ScriptErrorsSuppressed = True
 
Smile | :)
Generalcalling saveas(filename) run over code but not save anythingmemberjacodp2121 Sep '07 - 4:15 
Dim HTMLFileIn = path & "/compliance/ExportView.asp?complianceid=" & ComplianceID & "&path=" & path & "&constr='" & constr & "'"
Dim DocFileOut = ExportTo & "\" & ComplianceID.ToString & ".html"
 
webBrowserEx1.Navigate(HTMLFileIn)
 

webBrowserEx1.SaveAs(DocFileOut)
 
this is my code. even stepped into the procedure and the line
 
public void SaveAs(string filename)
{
object o = null;
this.ExecWB(SHDocVw.OLECMDID.OLECMDID_SAVEAS,SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER,filename,o);
}
 
runs without error. i also dont even get a dialog box for this wich i dont want anyway. please any assistance will be appreciated...
GeneralProblem in Using eventsmemberRocky718 Aug '07 - 23:10 
Hello
 
well first of all I gotta congratulate you on this suplended article.
 
I'm trying to use this control in my application. Its basically a log viewer and it also has a fuinction of showing the full XML file in the browser (your browser control). So far its going fine but the problem is that now I want to get a functionality that should give an option of Expand All and collapse all nodes for an XML document shown in the browser.
 
I was trying to test a few events of this control but no event is getting fired. I was thinking there could be an event when the user click inside the browser on lets say anywhere or on some link or xml node. but after implementing the events such as MouseDown, Click etc the application is giving no response.
 
Can u plz give some useful advice on that
 
Thank you
 
Rocky
NewsRe: Problem in Using eventsmemberRocky719 Aug '07 - 0:34 
well I got the mouse event fired up now.. thank fully ... still looking to get the nodes to collapse somehow.
QuestionError compiling the projectmemberKjp Inc.19 Jun '07 - 5:58 
My project checks for strong names in the assemblies and the created AxInterop.SHDocVw hasn't got a strong name in it.
 
It returns with the following error :
 
error CS1577: Assembly generation failed -- Referenced assembly 'AxInterop.SHDocVw' does not have a strong name
Confused | :confused:
 
Could someone please help me sort the problem.
 
Thanks a lot.
Generalrunning JavaScript in webBrowsermemberzilibaba6 Mar '07 - 4:37 
How can I run a custom JavaScript, not included in the webpage, that webBrowser is on now?
GeneralJavascript errormemberQaiseri5 Mar '07 - 10:15 
What about javascript errors? Can we supress those nasty error messages?
GeneralRe: Javascript errormemberMorningZ19 Mar '07 - 7:34 
I also am looking for the solution to suppressing Javascript errors
GeneralRe: Javascript errormembermakinaultral12 Nov '08 - 4:58 
private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
axWebBrowser.Silent =true
}
GeneralDisabling context menumembernitingautam5 Mar '07 - 3:12 
Hi,
 
I am using the Web Browser class provided with .NET 2.0. I had few queries related to how to implement certain features
 
1. I am using the Web Browser control to load flash files as well as HTML files. Whenever the browser loads html files I disable the context menu as
 
browserControl.IsWebBrowserContextMenuEnabled = false;
 
However when I load the flash file right clicking on the web browser control shows the context menu for the flash player. How can I block that as well.
 

thanks in advance

GeneralXP Theme not applied on dialog windows using showModalDialog()memberShazam3815 Feb '07 - 4:18 
Hi
 
Thanks for the great job you acheived doing this control which was very useful to me.
 
I use it to embed a web based app that uses modal dialogs via the JS showModalDialog() function and I noticed that XP style is not applied properly.
 
Do you have any idea about how to have the XP theme applied correctly on modal (or modeless) dialogs ?
 
regards

 
Shazam

Questionhow handling the onclick event on a IHTMLElement object ?:memberponciopancio14 Dec '06 - 6:23 
Hi,
I'm working in .NET framework programming a toolbar in c # for Internet explorer browser.
I would like to handle the onlclick event on an IHTMLElment object in the web document;
I found something in the following document http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21555434.html
but I can't view the solution
 
1) somebody konw the solution?
 
2) in the above document it's used the htmlElementEvents2_Event class; but I didn't find its documentation in http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/mshtml/reference/reference.asp
somebody knows how to find that?
 
somebody in help for me?any idea ? thanks in advance
 

AnswerRe: how handling the onclick event on a IHTMLElement object ?:memberlulacapixaba7 Nov '07 - 1:17 
The solution proposed is this one (By Erick37):  
 
Protected WithEvents my_element As mshtml.HTMLInputElementClass
 
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            wb.Navigate2("http://localhost/index.htm")
      End Sub
 
      Private Sub wb_DocumentComplete(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent) Handles wb.DocumentComplete
 
            Dim doc As mshtml.HTMLDocument
 
            doc = wb.Document
            my_element = doc.getElementById("mapimage")
 
      End Sub
 
      Private Function my_element_Event_onclick(ByVal pEvtObj As mshtml.IHTMLEventObj) As Boolean _
            Handles my_element.HTMLInputTextElementEvents2_Event_onclick
            Debug.WriteLine(pEvtObj.x.ToString & " : " & pEvtObj.y.ToString)
      End Function
 
Lula Capixaba
GeneralWebBrowserEx chokes on Javascript in templatesmemberpblecha8 Dec '06 - 7:14 
The problem is not in rendering; but what happens is, if there is javascript in the header of a page, it re-renders that page, making it impossible to add the URL of that page to, say, a Favorites menu.
 
Ideas/suggestions?
QuestionNavigate Problemmembertaiqi28 Nov '06 - 11:35 
I have stuck two weeks, I meet a problem when AxWebBrowserEx visit my Web Server by Navigate method. In the beginning, it's work, but after I navigate to some pages, then it's stuck my any input, I found the AxWebBrowser has fired the BeforeNavigation Event, And the web server has reponsed the request. But the AxWebBrowser didn't display any new information. I'm working on VS 2003 and .Net 1.1.
Could you please give me any ideal about it? Thanks a lot.
 

The code is:
 
this.axWebBrowser.Url = ...
 
while (this.webBrowser1.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
{
Application.DoEvents();
Thread.Sleep(50);
}
 

private void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e) {
this.OnDisplayComplete();
String sURL = (string) e.uRL;
if (sURL=="about:blank")
return;
 
}
 
private void axWebBrowser1_DisplayComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
this.OnDisplayComplete();
 
String sURL = (string) e.uRL;
if (sURL=="about:blank")
return;
}
QuestionHow to Add Onclick method on AXWebBrowser control??memberMystic_8 Oct '06 - 22:21 
How to Add Onclick method on AXWebBrowser control??
GeneralManaged to disable ALT keymemberthomas.oberndorfer28 Sep '06 - 3:30 
Hi!
 
First of all well done! Now lets get started:
 
You assume that the translator 'protected virtual uint OnTranslateAccelerator(ref tagMSG lpMsg, ref Guid pguidCmdGroup, uint nCmdID)' does not catch the ALT events, this is wrong.
 
The problem are the following lines:
 
int WM_KEYDOWN = 0x0100; // 256
if (lpMsg.message != WM_KEYDOWN)
throw new System.Runtime.InteropServices.COMException("", S_FALSE);

 
The ALT key causes another message code. The codes are shown below:
 
int ALT_KEYDOWN = 0x0104; // 260 ALT down
int ALT_KEYCMB = 0x0105; // 261 ALT up | ALT + anykey; not suitable for disabling ALT+LEFT,
//because the event occurs after the navigation,
//better: disable the whole ALT pressed handling

 
So if you add the following lines to the translator method (including the lines above) at the top all ALT stuff is disabled!
 
// ALT : ALT+LEFT or ALT+RIGHT for navigation
if(this.DisableAltKey && lpMsg.message == ALT_KEYDOWN)
throw new System.Runtime.InteropServices.COMException("", S_OK);

 
You can customize this by checking also the 'lpMsg.wParam' but for me this is perfect.
 
Just a nice html viewer Cool | :cool:
 
Enjoy!
GeneralDo not work RegisterAsBrowser and RegisterAsDropTargetmemberDima Filipiuk10 Sep '06 - 23:41 
Thanks for your control!;)
Can be because i work in .NET 2.0? I do not know.
I need to work with 2 control, and 1 window send url to 2 window.
This is work with axWebBrowser, and with IE this is work, but with this control not.
Help me please!Confused | :confused:

GeneralOS Compatibilitymembercspinelive17 Aug '06 - 4:11 
You mentioned that the 3 dlls you didn't include were OS specific. If I include them on my XP SP2 machine and get the program working, will the app still work if I deploy it to a sever with say Windows Server 2000 or 2003?
 
Justin
GeneralRe: OS Compatibilitymembercspinelive17 Aug '06 - 4:13 
What would be your suggested deployment strategy for a situation like this?
 
-Justin
QuestionHow to "POST" data? bug?memberpercyboy7 May '06 - 23:35 
I tried to use the "Navigate" method to POST data to a URL, but failed. The browser seemed only finishing the GET action but not POST action as I supposed.
 
Is it a bug?

AnswerRe: How to "POST" data? bug?memberpercyboy7 May '06 - 23:58 
I've just modified the Line 1280 of the WebBrowserEx.cs (in the method Navigate) as below:
 
object postDataObj = (postData != null ? System.Text.ASCIIEncoding.ASCII.GetBytes(postData) : null);
 
And after recompiling, the POST action seemed working. I suppose this is a small bug.
 

Best wishes!

GeneralDocument IssuesmemberYaron Shkop30 Apr '06 - 5:56 
The document is a way to explicitly load html into the browser, easpecially when you deal with local html files you want to display.
However, When doing it and not using the Navigate method the scrollbar stops reacting and if it does response then the document events stop working.
I believe these are the issues you have talked about but it make things very prblematic.
Generalthis.webBrowserEx1.Silent = true - does not seem to workmembergdfornutn5 Apr '06 - 7:21 
Let me first say the I really like the control. Many thanks Smile | :)
 
I have a project where I need to disable Ctrl+N, therefore I'm using the Extended web browser control. The problem is that some of the pages that the program browses has script errors. With a previous version of my code I used: "this.axWebBrowser.Silent = true;" which forced the axWebBrowser to ignore the errors (so the user doesn't have to click "Ok" many times). However when using this control "this.webBrowserEx1.Silent = true;" does not seem to work (maybe it does but not the same way). Does anyone know how I can tell webBrowserEx1 to ignore any script errors on a displayed web page?
 
thanks for your time.
 
Knute
 

-- modified at 13:21 Wednesday 5th April, 2006
GeneralRe: this.webBrowserEx1.Silent = true - does not seem to workmembermakinaultral12 Nov '08 - 4:59 
private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
axWebBrowser.Silent =true
}
QuestionTrying to Revoke a drop target that not been registeredmembercoolsap26 Mar '06 - 20:31 
Hi Everyone
 
I am opening a Word Document in a Web Browser and I need to print the Word Document by displaying the Print Dialog Box..
 
I tried using
 
axWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER)
where axWEbBrowser1 is the WebBrowser where i am displaying the Word Document...
 
But when the code is executed i am getting the following error...
 
Trying to Revoke a drop target that not been registered
 
Any help is greatly appreciated..
 
Saps
GeneralProxy problemsmembercdemez6 Mar '06 - 6:53 
Hi,
 
We are behind a proxy, IE is working correctly but it sounds that your application do not use the same proxy settings.
 
How can we change this automatically ? Do you know ?
 
Thanx
 
Krys
GeneralOpen Link when onlinememberder_alte_Sack25 Jan '06 - 7:08 
Hi Codefolkz,
 
i have used the control to build a very simplified browser. i have registered it as standardbrowser for html, http, https an so on. When i use this browser to open html files locally everthing works fine, i can open new windows and links without any problems but when i go online (local webserver or not makes no difference) links will not work. the request hangs a while an after this a message box with a javascript error appears. The same page is working fine from local harddisc. When i try to open a new window with 'window.open (..)' (JavaScript) or create a href which points to http://... the browser hangs a while but when i open the normal Internet Explorer the requested new window appears in a IE window additionally to the one i have opened.
Can everybody help me out ?
 
btw this is a great control and many thanks for it.
 
greetz
Gordon
GeneralExtended web browser control for .NET 1.0/1.1memberarpita_sw13 Jan '06 - 6:21 
Smile | :) Hi,
I am arpita ,a software developer from India.
I am using Extended web browser control for .NET 1.0/1.1
in my project but whenever I try to click on a link , link doesn't work. Can anybody help me ?
Thanks in advance.
Your arpita.
GeneralRe: Extended web browser control for .NET 1.0/1.1memberYaron Shkop30 Apr '06 - 6:05 
If you are using the document you are loosing the location idenrifier of your html source.
Therfor if you have relative links they are invalid.
You can add a <base href=''> tag to your html and supply the base directory or uri or replace the relative pathes to full pathes by string manipulations.
 
However, When you work with HtmlDocument you should register to the document click event and check if link was pressed:
 
//Register
webBrowserEx1.EnableHtmlDocumentEventHandling = true;
webBrowserEx1.HtmlDocumentClick += new WebBrowserExEventHandler(webBrowserEx1_HtmlDocumentClick);
 
//Response
IHTMLAnchorElement link = e.HtmlEventObj.srcElement as IHTMLAnchorElement;
if(link!= null)
{
.....
}
 
..
Questionhow 2 work with combo box using axWebBrowser1 ?membervedmack7 Jan '06 - 22:54 
for example in this site :
http://www.google.com/advanced_search?hl=en
 
how i can choose an option in any of the multiline combo boxes?
like Language, File Format.....
i mean for example in Language i wanna select some language
and in file format i wanna select pdf
 
thx in advance....
 

GeneralEnableHtmlDocumentEventHandling =true flase nto workingmemberanand15 Jan '06 - 3:58 
can anybody help to solve this problem . We are not adding anyspecial code just simple on btn click want EnableHtmlDocumentEventHandling=true and other btn click want EnableHtmlDocumentEventHandling=false
QuestionInvalidVariant MDA with .NET 2.0?memberJWenderoth28 Dec '05 - 7:04 
When I run the sample app in Debug and Browse to a site, I get an InvalidVariant MDA once the Browse is complete. Text of the MDA is:
InvalidVariant was detected
Message: An invalid VARIANT was detected during a conversion from an unmanaged VARIANT to a managed object. Passing invalid VARIANTs to the CLR can cause unexpected exceptions, corruption or data loss.
 
Anyone else see this? Any solutions for it?
 
--Jered
 
-- modified at 13:38 Thursday 29th December, 2005
AnswerRe: InvalidVariant MDA with .NET 2.0?membervinej7 Mar '06 - 13:52 
I have the same problem
 
Somebody found a solution ?
GeneralRe: InvalidVariant MDA with .NET 2.0?memberTindaloo18 Dec '06 - 21:59 

http://blogs.msdn.com/yangxind/archive/2006/03/21/556837.aspx
 
Here is the right solution:
 
Bring up the Debug -> Exceptions dialog. Under Managed Debugging Assistants, uncheck the InvalidVariant MDA.
QuestionHow can I disable JavaScript error messages?memberodical14 Dec '05 - 15:31 
Is there an example of how to get the browser control to ignore JavaScript error messages and continue displaying the page? Currently each javascript error will give a popup and ask you if you want to continue or stop processing. This particular control seems like a very good one since it implements a lot of work arounds that I have seen, but it does not seem to have the a way to ignore these messagebox's and continue processing the page.
 

 
Shawn
AnswerRe: How can I disable JavaScript error messages?memberhkulten20 Dec '05 - 0:28 

Hi,
 
I don't have the answer, but I am searching for a way to intercept Javascript errors too. I tried to implement the IOleCommandTarget interface and the two methods Exec and QueryStatus in order to check the OLECMDID_SHOWSCRIPTERROR value, but I have an initialization error of my application using the WebBrowserEx component. D'Oh! | :doh:
 
Is anyone have an idea?
 
Thanks.
GeneralRe: How can I disable JavaScript error messages?memberKoaQiu28 Dec '05 - 16:30 
search the JavaScript error messages window
and Kill it.
 
or
PSS ID Number: Q261003
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/enu_kbie_dev/en-us/ie_dev/Q261003.htm
Generalalready complied versionmemberrobertw01911 Dec '05 - 9:14 
is there any chance you could provide a already complied version of this control in zip file?
Question.Net 2.0 WebBrowser.document.designmode = 'On';memberphanf8 Dec '05 - 3:51 
Has anyone been able to get WebBrowser1.DesignMode = "On" to work with the .net 2.0 WebBrowser Control? I found the following code, but was unable to get it to work, as anyone else attempted this?
 
http://weblogs.asp.net/hpreishuber/archive/2005/07/13/419281.aspx
 
Dim axObj As New Object
axObj = WebBrowser1.ActiveXInstance
axObj.document.designmode = "On"

 
phanf
AnswerRe: .Net 2.0 WebBrowser.document.designmode = 'On';memberLiuZhijun3 Jan '06 - 18:14 
mshtml.HTMLDocument hDoc = (mshtml.HTMLDocument)WB.Document.DomDocument;
hDoc.designMode = "On";
 
or
 
w1.Document.DomDocument.GetType().GetProperty("designMode").SetValue(w1.Document.DomDocument, "On", null);

Questionabout on DocumentComplete event in c#memberlogiccreator7 Dec '05 - 18:59 
i want to implement this check in c# to check when finally page is completed.i also read the article "How To Determine When a Page Is Done Loading in WebBrowser Control" http://support.microsoft.com/kb/q180366/ but i cannot implement this in c#.How can i implement this check in CSHARP.
 
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object,
URL As Variant)
If (pDisp Is WebBrowser1.Object) Then
Debug.Print "Web document is finished downloading"
End If
End Sub
 
-- modified at 1:43 Thursday 8th December, 2005
AnswerRe: about on DocumentComplete event in c#memberphanf8 Dec '05 - 3:42 
Once possible solution is to move to the new .Net 2.0 webbrowser control, there a many events inluded within the control.
 
phanf
GeneralCurrentDocument errormemberRitcho19 Nov '05 - 17:15 
Hi,
 
If you hit "Write some HTML" first, before doing anything else, I think the program crashes, as CurrentDocument has not been initialized. I'm trying to work out how to initialize CurrentDocument presently...
GeneralRe: CurrentDocument errormemberGianni Gardini 221 Sep '06 - 5:46 
This is the fix for the problem.
(Thanks to code and info you can see here:

http://www.windowsforms.net/FAQs/default.aspx?PageID=3&CategoryID=3&SubcategoryID=41&tabindex=3
)
 
Replace:
public mshtml.IHTMLDocument2 CurrentDocument
{
...
}
 

With:

public mshtml.IHTMLDocument2 CurrentDocument
{
get
{
try
{
if(!initialized)
{
initialized = true;
InitBrowser();
}
 
mshtml.IHTMLDocument2 htm = (mshtml.IHTMLDocument2) this.axWebBrowser.Document;
return htm;
}
catch
{
return null;
}
}
}

 

Then add the following code:

private const string K_StartUrl = "about:blank";
private const int OLEIVERB_UIACTIVATE = -4;
private bool initialized = false;
 

///
/// Set the CurrentDocument's html.
///

[
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
Description("Sets the current HTML")
]
public string Html
{
set
{
this.CurrentDocument.write(value);
UIActivate();
}
}
 

private void InitBrowser()
{
object flags = 0;
object targetFrame = string.Empty;
object postData = string.Empty;
object headers = string.Empty;
axWebBrowser.Navigate(K_StartUrl, ref flags, ref targetFrame, ref postData, ref headers);

MethodInvoker mi = new MethodInvoker(this.DelayedInitialize);
this.BeginInvoke(mi);
}
 
private void DelayedInitialize()
{
UIActivate();
}
 
private void UIActivate()
{
axWebBrowser.DoVerb(OLEIVERB_UIACTIVATE);
}

 
Then replace in Form1.cs:
this.webBrowserEx1.CurrentDocument.write("<html>click here</html>");
 
With:
this.webBrowserEx1.Html = "<html>click here</html>";
 

 

GeneralCRASH - NullReference Exception - Fixmemberrichie5um7 Nov '05 - 23:48 
Hi,
 
I was getting a crash with a specific link on my Win2K box. The following needs to be fixed in your implementation.
 
private const int E_NOINTERFACE = unchecked((int)0x80004002);
private const int E_NOTIMPL = unchecked((int)0x80004001);
 

int IOleClientSite.GetMoniker(uint dwAssign, uint dwWhichMoniker, out Object ppmk)
{
ppmk = null;
 
return E_NOTIMPL;
}
 
int IOleClientSite.GetContainer(out IOleContainer ppContainer)
{
ppContainer = null;
 
return E_NOINTERFACE;
}
 
RichS.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 12 Dec 2004
Article Copyright 2004 by yetanotherchris
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid