Click here to Skip to main content
12,358,497 members (62,492 online)
Click here to Skip to main content
Add your own
alternative version

Stats

21.5K views
5 bookmarked
Posted

How to Close the Browser Window from a Silverlight Application

, 9 Aug 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
If you are developing a secured site and want to close the browser window just after the user logs out from the application, this small tip will help you.

Almost all secured sites like bank websites ask you to close your browser window after you sign out from a web application. This is a security measure which actually removes all session details from the browser cache.

If you want to develop the same behavior in your Silverlight application, how will you do this? This post covers the code to implement this functionalityRead to know more.

If you are developing a secured site and want to close the browser window just after the user logs out 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 the "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 Internet Explorer, it will ask 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_3_.png

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

_Kunal Chowdhury_
Software Developer (Senior)
India India
Kunal Chowdhury is a Microsoft "Windows Platform Development" MVP (Most Valuable Professional), a Codeproject Mentor, Telerik Developer Expert, Nokia Developer Champion, Windows 10 Champion, Microsoft Rockstar, Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession.

He is currently working in an MNC located in India. He has a very good skill over XAML, C#, Silverlight, Windows Phone, WPF and Windows Store (WinRT) app development. He posts his findings, articles, tutorials in his technical blog and CodeProject.

Technical Blog: http://www.kunal-chowdhury.com
Facebook: http://facebook.com/blog.kunal
Twitter : http://twitter.com/kunal2383

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 9 Aug 2011
Article Copyright 2011 by _Kunal Chowdhury_
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid