Page view counter

Silverlight Tips of the Day - Blog by Mike Snow

Game Programming with Silverlight

Silverlight Tip of the Day #52 – How to Popup a Browser Window

Let’s say a user clicks on a button and you want to popup a separate browser and point them to a specific web page. How do you do this in Silverlight?

Silverlight now supports a method called HtmlPage.PopupWindow(). For security reasons this call can only be made in response to any user input such as a button click.

To use this method you will need to add a reference to System.Windows.Browser;

The call to HtmlPage.PopupWindow() takes three parameters:

  1. Uri – The location to browse to (I.e http://www.silverlight.net).
  2. String – The name you want to call the target window.
  3. HtmlPopupWindowOptions – A variety of options such as window positioning, sizing. Also, whether the toolbar and menubar are visible and more.

The following code demonstrates how to do this in response to a button click from the user:

private void Button_Click(object sender, RoutedEventArgs e)
{
    HtmlPopupWindowOptions options = new HtmlPopupWindowOptions();
 
    options.Left = 0;
    options.Top = 0;
    options.Width = 800;
    options.Height = 600;
 
    if(true == HtmlPage.IsPopupWindowAllowed)
        HtmlPage.PopupWindow(new Uri("http://www.silverlight.net"), "new", options);
}

*Note: This method is not supported in Safari because it does not implement the right NPAPI contract.

Thank you,
--Mike Snow

 Subscribe in a reader

Comments

Microsoft Weblogs said:

Let’s say a user clicks on a button and you want to popup a separate browser and point them to a specific

# September 30, 2008 1:58 PM

rachidadukes@live.com said:

Your tips are short, and useful.

Thanks for the good work.

Rachida Dukes

# September 30, 2008 7:46 PM

Dew Drop – September 30, 2008 (Evening Edition) | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Drop – September 30, 2008 (Evening Edition) | Alvin Ashcraft's Morning Dew

# September 30, 2008 10:29 PM

aashishkrishnan said:

what's the assembly namespace we have to refer?

# October 1, 2008 12:18 AM

2008 October 01 - Links for today « My (almost) Daily Links said:

Pingback from  2008 October 01 - Links for today « My (almost) Daily Links

# October 1, 2008 3:56 AM

Silverlight news for October 1, 2008 said:

Pingback from  Silverlight news for October 1, 2008

# October 1, 2008 4:58 AM

GearWorld said:

Welcome advertisements

Ahhh man I'm tired of them.

# October 1, 2008 6:34 AM

Community Blogs said:

In this post: Mike Snow, Bill Reiss, Jesse Liberty, Harsh Bardhan, Tim Heuer, Matthias Shapiro, and Jeff

# October 1, 2008 9:54 AM

Mirrored Blogs said:

Post: Approved at: Oct-8-2008 Tip:How to Popup a Browser Window "Let’s say a user clicks on a button

# October 8, 2008 5:50 AM

Visual Web Developer Team Blog said:

Silverlight Tip of the Day #57 Title: How to Dynamically Load a Silverlight Control within another Silverlight

# October 8, 2008 11:05 PM

MS Tech News » Silverlight Tips of the Day ??? Week 8 said:

Pingback from  MS Tech News » Silverlight Tips of the Day ??? Week 8

# October 27, 2008 3:26 PM

MS Tech News » Silverlight Tips of the Day ??? Week 8 said:

Pingback from  MS Tech News » Silverlight Tips of the Day ??? Week 8

# October 27, 2008 3:32 PM

Silverlight Tips of the Day - Blog by Mike Snow said:

The purpose of this post is to create an outline summary all the blogs from my Silverlight tips of the

# January 2, 2009 5:56 PM

o UAU nosso de cada dia said:

essa lista eu copiei desse blog bárbaro (acompanhe por RSS você também): uma lista de dicas super úteis

# January 3, 2009 6:25 AM

??????????????? ??? ?????? « jin_u as blog said:

Pingback from  ??????????????? ??? ?????? « jin_u as blog

# March 24, 2009 10:02 PM

rishi23 said:

Hi do you know a way where in I can open a PDF document in the popup ??

I am using silverlight3 and there is this PopUpWindow that I can open anywhere, but I am not sure how to open a document in the window.

# September 24, 2009 11:49 AM