Thursday, August 25, 2011

How to Close the Browser Window from a Silverlight Application

All secured sites 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 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. If you want to develop the same behavior in your Silverlight application, this is how we can do the trick.

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 OnWindowCloseClick(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

Monday, August 01, 2011

Tips for Cross Browser Compatibility

Cross-browser compatibility is one of the most time consuming tasks for any web designer. We’ve seen many different articles over the net describing common problems and fixes. There are some things you should consider for Safari and Firefox also, and IE isn’t always the culprit for your CSS woes. Here is a quick summary of How to get Cross Browser Compatibility Every Time:

  • Always use strict doctype and standards-compliant HTML/CSS
  • Always use a reset at the start of your css
  • Use -moz-opacity:0.99 on text elements to clean up rendering in Firefox, and text-shadow: #000 0 0 0 in Safari
  • Never resize images in the CSS or HTML
  • Check font rendering in every browser. Don’t use Lucida
  • Size text as a % in the body, and as em’s throughout
  • All layout divs that are floated should include display:inline and overflow:hidden
  • Containers should have overflow:auto and trigger hasLayout via a width or height
  • Don’t use any fancy CSS3 selectors
  • Don’t use transparent PNG’s unless you have loaded the alpha