Creating Chrome Control In SharePoint 2013 App

Introduction

In this article, I am going to explain how we can create our Chrome Control in SharePoint 2013 App. This custom Chrome Control will help in navigating between the pages (just like a menu), we can also include our project images like project/App logo.

Steps to Create Custom Chrome Control in App

Inthe below solution I am going to create a SharePoint App which contains multiple pages, and I am going place my custom Chrome control in the body content to navigate between the pages, and also add my App logo in the Chrome control.

Steps: 1

Create SharePoint 2013 APP ‘AppCromeControl’,

AppCromeControl

Step: 2

Add html pages in the pages folder (here I have added About, Accounts and Help html pages).

pages

Step: 3

Add below div code to place our Chrome control,

  1. <asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">  
  2.     <div id="chrome_ctrl_placeholder"></div>  
  3.     <div>  
  4.         <p id="message">  
  5.             <!-- The following content will be replaced with the user name when you run the app - see App.js -->  
  6.             initializing...  
  7.         </p>  
  8.     </div>  
  9.   
  10. </asp:Content>  
Step: 4

Add below JavaScript code in App.js file in scripts folder to create custom Chrome control,
  1. var hostWebUrl;  
  2. $(document).ready(function () {  
  3.     hostWebUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));  
  4.     var scriptbase = hostWebUrl + "/_layouts/15/";  
  5.     $.getScript(scriptbase + "SP.UI.Controls.js", renderChrome);  
  6. });  
  7.   
  8. function getQueryStringParameter(paramToRetrieve) {  
  9.     var params =  
  10.         document.URL.split("?")[1].split("&");  
  11.     var strParams = "";  
  12.     for (var i = 0; i < params.length; i = i + 1) {  
  13.         var singleParam = params[i].split("=");  
  14.         if (singleParam[0] == paramToRetrieve)  
  15.             return singleParam[1];  
  16.     }  
  17. }  
  18.   
  19. function renderChrome() {  
  20.   
  21.     var options = {  
  22.         "appIconUrl""../Images/RKAppImg.png",  
  23.         "appTitle""Chromecontrol Demo",  
  24.         "appHelpPageUrl""Help.html?"  
  25.             + document.URL.split("?")[1],  
  26.         "settingsLinks": [  
  27.             {  
  28.                 "linkUrl""Accounts.html?"  
  29.                     + document.URL.split("?")[1],  
  30.                 "displayName""Account settings"  
  31.             },  
  32.             {  
  33.                 "linkUrl""About.html?"  
  34.                     + document.URL.split("?")[1],  
  35.                 "displayName""About us"  
  36.             }  
  37.         ]  
  38.     };  
  39.     var nav = new SP.UI.Controls.Navigation(  
  40.                            "chrome_ctrl_placeholder",  
  41.                            options  
  42.                      );  
  43.     nav.setVisible(true);  
  44. }  
Step: 5

Browse the App and you can see newly created Chrome control, if you click on the right site setting image (which is highlighted) you can find the pages links to navigate the pages.

pages

pages

pages

pages
 
I hope this article will help you in creating Chrome control, this is the common code to create across the projects, please leave your valuable comments t help me improve. Happy coding!!

Read more articles on SharePoint:

Up Next
    Ebook Download
    View all
    Learn
    View all