Jennifer Marsman

Windows Development

IE Pinned Sites Part 9: Patterns to make your pinned site code play nice in all browsers

IE Pinned Sites Part 9: Patterns to make your pinned site code play nice in all browsers

  • Comments 0

In the last 4 blog posts, I’ve demonstrated using JavaScript to create various experiences in your pinned site (dynamic Jump List categories, overlay icons, thumbnail toolbar buttons, and flashing taskbar buttons). 

You may have been wondering if this JavaScript would play nicely in a browser other than Internet Explorer 9.  Fair question!  In this post, I’ll show you two patterns for making your pinned site code play nice in all browsers. 

 

Pattern 1

The first pattern is a try/catch pattern.  Wrap your existing pinned site code inside the try block.  Errors will be swallowed in the catch block.

try {
    if (window.external.msIsSiteMode()) {
        // Your pinned site code goes here.
    }
}
catch (e) { }
 

Pattern 2

The second pattern checks for the existence of the msAddSiteMode type before proceeding. 

if (typeof window.external.msAddSiteMode != "undefined") {
    // SiteMode is supported 
    if (window.external.msIsSiteMode()) {
        // Your pinned site code goes here.
    }
} 

 

For example, here is one of the scripts from the Windows Development Boot Camp site. 

<script type="text/javascript">
    // Jump list categories
    if (window.external.msIsSiteMode()) {
        window.external.msSiteModeCreateJumplist('Resources');
        window.external.msSiteModeAddJumpListItem('Jennifer Blog', 'http://blogs.msdn.com/jennifer', 'http://windowsdevbootcamp.com/favicon.ico');
        window.external.msSiteModeAddJumpListItem('Twitter', 'http://www.twitter.com/windevbootcamp', 'http://a3.twimg.com/a/1294164987/images/iefavicon.ico');
        window.external.msSiteModeAddJumpListItem('Silverlight 4', 'http://bit.ly/dvR7Hb', 'http://windowsdevbootcamp.com/favicon.ico');
        window.external.msSiteModeAddJumpListItem('Internet Explorer 9', 'http://bit.ly/b9HBZu', 'http://windowsdevbootcamp.com/favicon.ico');
        window.external.msSiteModeAddJumpListItem('Windows 7 Training Kit for Developers', 'http://bit.ly/cXaJ1u', 'http://windowsdevbootcamp.com/favicon.ico');
        window.external.msSiteModeAddJumpListItem('Windows API Code Pack', 'http://bit.ly/bGKULt', 'http://windowsdevbootcamp.com/favicon.ico');
        window.external.msSiteModeShowJumplist();
    }
</script>

If I leave the script like that, it will throw an error (which I can see in Firebug) when I open the site in Firefox.  (Note that this error is suppressed if a non-developer user opened the site in Firefox normally, so they wouldn’t see anything.  But using Firebug, we can see that there is an error.) 

FirebugException

Now, let me wrap the script with one of the patterns described above.

<script type="text/javascript">
    // Jump list categories
    if (typeof window.external.msAddSiteMode != "undefined") {
        if (window.external.msIsSiteMode()) {
            window.external.msSiteModeCreateJumplist('Resources');
            window.external.msSiteModeAddJumpListItem('Jennifer Blog', 'http://blogs.msdn.com/jennifer', 'http://windowsdevbootcamp.com/favicon.ico');
            window.external.msSiteModeAddJumpListItem('Twitter', 'http://www.twitter.com/windevbootcamp', 'http://a3.twimg.com/a/1294164987/images/iefavicon.ico');
            window.external.msSiteModeAddJumpListItem('Silverlight 4', 'http://bit.ly/dvR7Hb', 'http://windowsdevbootcamp.com/favicon.ico');
            window.external.msSiteModeAddJumpListItem('Internet Explorer 9', 'http://bit.ly/b9HBZu', 'http://windowsdevbootcamp.com/favicon.ico');
            window.external.msSiteModeAddJumpListItem('Windows 7 Training Kit for Developers', 'http://bit.ly/cXaJ1u', 'http://windowsdevbootcamp.com/favicon.ico');
            window.external.msSiteModeAddJumpListItem('Windows API Code Pack', 'http://bit.ly/bGKULt', 'http://windowsdevbootcamp.com/favicon.ico');
            window.external.msSiteModeShowJumplist();
        }
    }
</script>

If I open the site using Firefox again, I don’t see any errors in Firebug. 

FirebugClean

In my final post tomorrow, we will wrap up this IE Pinned Site series with some pinned site resources. 

 

Other Blog Posts in this Series

IE Pinned Sites Part 1: What Are Pinned Sites?

IE Pinned Sites Part 2: Why Implement Pinned Sites?

IE Pinned Sites Part 3: How to implement basic site properties

IE Pinned Sites Part 4: How to implement Jump List Tasks

IE Pinned Sites Part 5: How to implement dynamic Jump List Categories

IE Pinned Sites Part 6: How to implement Overlay Icons

IE Pinned Sites Part 7: How to implement Thumbnail Toolbar Buttons

IE Pinned Sites Part 8: How to implement a Flashing Taskbar Button

IE Pinned Sites Part 9: Patterns to make your pinned site code play nice in all browsers

IE Pinned Sites Part 10: Pinned Site Resources

  • Loading...
Leave a Comment
  • Please add 1 and 3 and type the answer here:
  • Post