Silverlight url public link blocked by browser

The problem is simple but annoying. I have a button and the click event just opens a link

HtmlPage.Window.Navigate(uri, "_blank"); 

But it continues to be blocked by the browser. I searched a lot. Everyone seems to be using this method, but no one has mentioned that the new tab / window is locked. So what should I do?

UPDATE

The problem is resolved. It seems like you should use HyperlinkButton to go to external web pages. This is not blocked by the browser.

"To enable user navigation on other web pages, you can use the HyperlinkButton control and set the NavigateUri property to an external resource and set the TargetName property to 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 having the user manually disable the block.

+4
source share
3 answers

Have you considered System.Windows.Browser.HtmlPage.PopupWindow(uri, "_blank", null) in Silverlight 3 and 4?

Instead of the last zero, you can also set the parameter set via HtmlPopupWindowOptions

+1
source

You can use System.Windows.Browser. HtmlPage.Window.Eval as follows:

  HtmlPage.Window.Eval("mywindowopener('http://www.google.com'") 

to call the javascript function "mywindowopener" and pass the url. Then in your Javascript:

  function mywindowopener(uri) { window.loginDialog = window.open(uri, "popupwindow", "height=320,width=480,location=no,menubar=no,toolbar=no"); } 

"HtmlPage.Window.Eval" bypasses the popup blocker, while "HtmlPage.Window.Invoke (mywindowopener, url)" or "HtmlPage.PopupWindow" will not.

+1
source

Silverlight Code:

  public static void OpenWindow(string url, WindowTarget target = WindowTarget._blank) { // This will be blocked by the pop-up blocker in some browsers // HtmlPage.Window.Navigate(new Uri(url), target.ToString()); // Workaround: use a HyperlinkButton, but do make sure for IE9, you need to have // <meta http-equiv="x-ua-compatible" content="IE=8" /> // and for all browsers, in the Silverlight control: // <param name="enableNavigation" value="true" /> // Also, it seems the workaround only works in a user-triggered event handler // // References: // 1. http://stackoverflow.com/questions/186553/sending-a-mouse-click-to-a-button-in-silverlight-2 // 2. http://stackoverflow.com/questions/14678235/silverlight-hyperlinkbutton-not-working-at-all HyperlinkButton hb = new HyperlinkButton() { NavigateUri = new Uri(url), TargetName = target.ToString() }; (new HyperlinkButtonAutomationPeer(hb) as IInvokeProvider).Invoke(); } 

Html page containing a Siverlight control:

 <!-- http://stackoverflow.com/tags/x-ua-compatible/info X-UA-Compatible is a IE-specific header that can be used to tell modern IE versions to use a specific IE engine to render the page. For example, you can make IE8 use IE7 mode or tell IE to use the newest available rendering engine. --> <meta http-equiv="x-ua-compatible" content="IE=8" /> <!-- If we don't have the the above meta tag, Silverlight HyperlinkButton won't work in IE9 Some Security issue (Unathorized access exception) TODO: 1. Check if IE10 has the same issue or not; 2. Test this in IE7 or IE6. --> 
0
source

All Articles