Tuesday, October 28, 2008

Silverlight 2 URL Redirection

So in Silverlight 2 for some time we could do this:

System.Windows.Browser.HtmlPage.Window.Navigate(new Uri("foobar.com"), "_blank");

well this is all good and works but in some cases in IE when redirecting to a url that is not a page but a binary of some kind there seems to be an issue with opening the file and the browser window closes. ???

since I don't have time to work out if this is a bug or not or some 'feature'... Here is my cheater method that seems to work fine...

so I added this to the App:

public static void InsertECMAScript(string JavaScript)
HtmlElement Script = HtmlPage.Document.CreateElement("script");
Script.SetAttribute("type", "text/javascript");
Script.SetProperty("text", JavaScript);

and then from my user control I added this:

App.InsertECMAScript("ProcessWindowOpen(\"" + URL + "\");");

and poof it goes away....??? not sure what is up with that but works.