วันพุธที่ 16 พฤษภาคม พ.ศ. 2555

How to Silverlight application close browser?

What do you mean by "terminate the application"? Do you want to close your browser window or you want to take the user to another page outside of your silverlight application?
If you want to close the browser window, put the following code to the button click event handler:

HtmlPage.Window.Invoke("CloseWindow");

and put a CloseWindow javascript function on your page:

function CloseWindow()
{
window.close();
}

If you want to take the user to another page:
HtmlPage.Window.Navigate(new Uri("SomeUrl));

If you are developing a secured site and want to close the browser window just after the user logout from the application, this small tip will help you. This is not a difficult job to implement. Just a single line of code will do the trick for you.

Use "System.Windows.Browser.HtmlPage.Window.Invoke()" method to call the Close() method of the browser window as shown in the below code snippet:
 
private void OnCloseClick(object sender, RoutedEventArgs e)
{
    System.Windows.Browser.HtmlPage.Window.Invoke("close");
}


The above code when called will close the browser window where your Silverlight application is hosted. If it is a tab, it will close the Window tab instead. If you are using it inside the Internet Explorer, it will confirm you whether you really want to close the browser. If you press "No", it will remain in that page and clicking "Yes" will close the browser tab/window.

SNAGHTMLfcd46a3

ไม่มีความคิดเห็น:

แสดงความคิดเห็น