In this artilce we will explore how to add site in the start menu using IE9. The adding of site in start menu is quite interesting. It allows to make your site to work as application.

If you look at the above screenshot there are two sections
1. Articles you like to read
2. Tasks
Whenever you open this site from start menu, the "Articles you like to read" will change but "Tasks" will remain same.
Let's see how we can do this
Step 1: To add the URLs as Task in the Start Menu we need to use msapplication-task as meta name. To add tooltip we need to use msapplication-tooltip. To give the size of the window we need to use msapplication-window. To provide application name of the added site in the start menu we need to use application-name.
<meta name="application-name" content="dotnetspeaks.com - All about .NET articles!" /> <meta name="msapplication-tooltip" content="dotnetspeaks.com - All about .NET articles!" /> <meta name="msapplication-window" content="width=1500;height=900" /> <meta name="msapplication-task" content="name=ASP.NET;action-uri=../Default.aspx?Category=ASP.NET;icon-uri=../../images/sumit-fav.ico" /> <meta name="msapplication-task" content="name=Ajax;action-uri=../Default.aspx?Category=Ajax;icon-uri=../../images/sumit-fav.ico" /> <meta name="msapplication-task" content="name=SQL;action-uri=../Default.aspx?Category=SQL;icon-uri=../../images/sumit-fav.ico" /> <meta name="msapplication-task" content="name=Miscellaneous;action-uri=../Default.aspx?Category=Miscellaneous;icon-uri=../../images/sumit-fav.ico" />
Step 2: Now, we will add dynamic content in the start menu on click of Add below Home link. Prior to adding a site in the start menu we need to check whether it is IE9 or not. Below code will check whether browser is IE or not . If it is IE which version. If it is IE then only provide the option of adding site in the start menu.
function getInternetExplorerVersion() { var rv = -1; // Return value assumes failure. if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) rv = parseFloat(RegExp.$1); } return rv; }
var ver = getInternetExplorerVersion();
if (ver === 9.0) { if (!window.external.msIsSiteMode()) { document.getElementById("divIE9").style.display = "block"; } }
Step 3: Now on click of Add the below javascript method will add the site to start menu.
function addToStartMenu() { try { if (!window.external.msIsSiteMode()) { window.external.msAddSiteMode(); } } catch (ex) { // Add site to start menu not supported } }
Below dialog will be prompted for confirmation.

Step 4: Step 1 and Step2 will occur only first time when you add the site in the start menu. Now as our content needs to be change dynamically we need add to start menu on every window load. Below is the code snippet to create dynamic links.
window.onload = function() { try { if (window.external.msIsSiteMode()) { window.external.msSiteModeClearJumplist(); window.external.msSiteModeCreateJumplist("Articles you like to read"); window.external.msSiteModeAddJumpListItem("URL Text", "URL", "favicon path"); } window.external.msSiteModeShowJumplist(); // Continue initialization. } catch (ex) { // Fail silently. } }
Below is the code snippet i haved used to make it work as per my requirement.
window.onload = function() { try { if (window.external.msIsSiteMode()) { var articleId = document.getElementById("<%=hidArticleId.ClientID%>").value.split(";"); var articleText = document.getElementById("<%=hidArticleText.ClientID%>").value.split(";"); var len = articleId.length; window.external.msSiteModeClearJumplist(); window.external.msSiteModeCreateJumplist('Articles you like to read'); for (i = 0; i < len; i++) { window.external.msSiteModeAddJumpListItem(articleText[i], 'http://www.dotnetspeaks.com/DisplayArticle.aspx?ID=' + articleId[i], '../../images/sumit-fav.ico'); } window.external.msSiteModeShowJumplist(); // Continue initialization. } } catch (ex) { // Fail silently. } }
Now you can click on the "Add" to add the site in your start menu.
This ends the article of adding site to start menu in IE9.
|