Launching Internet Explorer without address bar in .NET

I needed to launch an Internet Explorer window to a particular URL in a near “chromeless” fashion – no toolbar, no address bar, no scrollbars, from a C# .NET application. At first I used thread.start(url), but you cannot specify how Internet Explorer should open – there are no command line options to customize the window.

The internet failed me – I was supposed to reference some web COM dll, that I didn’t even have.

The solution is painfully simple. Make sure you have a reference to System.Windows.Forms, create a WebBrowser object in code (no need to add it to a form), give it an about:blank url, then use Document.Window.OpenNew() to launch a new IE window with parameters.

 

Examples speak louder than words: this snippet will open google in a new browser window

using (WebBrowser wb = new WebBrowser())
{
    wb.Url = new System.Uri("about:blank");
    wb.Document.Window.OpenNew("http://google.com", "location=no,menubar=no,scrollbars=no,status=yes,toolbar=no,resizable=yes");
}

If you will be opening a lot of windows, maybe you should keep the WebBrowser object in a class variable.

Maybe this one was out there somewhere, but I couldn’t find it…

2 thoughts on “Launching Internet Explorer without address bar in .NET

  1. Very nice! But there is one problem (at least with IE v8). If user presses F11 on the keybord then he will gain access to address bar, navigation buttons, reload and cancel buttons.

    Is there any option to lock this “F11 behaviour”?

  2. http://msdn.microsoft.com/en-us/library/ms159568.aspx
    this page has the full set of windowOptions… there does not appear to be an option that would prevent F11 (or F12 for that matter).

    However, you might experiment with setting options on the WebBrowser object (http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx)

    Or, as a last resort, I believe Internet Explorer prevents such things in modal windows (I know it prevents F12 debugging…) – as far as I can find you must use javascript to open such windows using the window.showModalDialog() function. (http://msdn.microsoft.com/en-us/library/ie/ms536759(v=vs.85).aspx)

    Hope that helps!

Leave a Reply