Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How To Close A Browser Window From A Silverlight Application

DZone's Guide to

How To Close A Browser Window From A Silverlight Application

· Mobile Zone
Free Resource

Launching an app doesn’t need to be daunting. Whether you’re just getting started or need a refresher on mobile app testing best practices, this guide is your resource! Brought to you in partnership with Perfecto

All most all secured sites like bank websites asks you to close your browser window after you signed out from the web application. This is due to high security 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 the functionality of the same. Read to know more.

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

Keep up with the latest DevTest Jargon with the latest Mobile DevTest Dictionary. Brought to you in partnership with Perfecto.

Topics:

Published at DZone with permission of Kunal Chowdhury, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}