The problem is simple but annoying. I have a button and the click event just opens a link by
HtmlPage.Window.Navigate(uri, "_blank");
But it keeps being blocked by the browser. I searched a lot. It seems everyone is using this method but no one mentioned the new tab/windows is being blocked. So what should I do?
UPDATE
Problem solved. It seems that to navigate to outside web pages, HyperlinkButton should be used. This is not blocked by the browser.
"To enable user navigation to other Web pages, you can use the HyperlinkButton control and set the NavigateUri property to the external resource and set the TargetName property to open a new browser window." --- MSDN, Silverlight - External navigation
<HyperlinkButton NavigateUri="http://www.microsoft.com" Content="Go to Microsoft" TargetName="_blank" />
PS. HtmlPage.PopupWindow is also blocked by the browser. It seems to me that HtmlPage.Window.Navigate and HtmlPage.PopupWindow are useless without the user manually disable the block.
Have you considered
System.Windows.Browser.HtmlPage.PopupWindow(uri, "_blank", null)
in Silverlight 3 and 4?Instead of the last null, you can also set a bunch of options via HtmlPopupWindowOptions
You can use System.Windows.Browser.HtmlPage.Window.Eval like this:
to call a javascript function "mywindowopener" and pass a URL. Then in your Javascript:
"HtmlPage.Window.Eval" will bypass the popup blocker whereas "HtmlPage.Window.Invoke(mywindowopener,url)" or "HtmlPage.PopupWindow" will not.
Silverlight Code:
Html Page containing the Siverlight control: