Add CSS Refrence in SharePoint 2013 App

You can reference a CSS or Style Sheet that is deployed in 15 hive in your SharePoint App using the Script below.

 <!-- Script to load SharePoint resources --> 
    <script type="text/javascript"> 
        var hostweburl; 
 
        (function () { 
            //Get the URI decoded URL. 
            hostweburl = 
                decodeURIComponent( 
                    getQueryStringParameter("SPHostUrl") 
            ); 
 
 
            // resources are in URLs in the form: 
            // web_url/_layouts/15/resource 
            var scriptbase = hostweburl + "/_layouts/15/"; 
 
            var dclink = 
                document.createElement("link"); 
            dclink.setAttribute("rel""stylesheet"); 
            dclink.setAttribute("href", scriptbase + "defaultcss.ashx"); 
            var head = document.getElementsByTagName("head"); 
            head[0].appendChild(dclink); 
        })(); 
 
        // Function to retrieve a query string value. 
        // For production purposes you may want to use 
        //  a library to handle the query string. 
        function getQueryStringParameter(paramToRetrieve) { 
            var params = 
                document.URL.split("?")[1].split("&"); 
            var strParams = ""; 
            for (var i = 0; i < params.length; i = i + 1{ 
                var singleParam = params[i].split("="); 
                if (singleParam[0] == paramToRetrieve) 
                    return singleParam[1]; 
            } 
        } 
    </script> 


0 comments:

Post a Comment

Popular Posts