我正在开发 SharePoint 2013 托管应用程序。
我想在我的应用程序中使用样式网站的颜色。
如何使用JS检索网站使用的样式信息?
谢谢,恩克

有帮助吗?

解决方案

要使用主机 Web 的颜色,您需要使用一些 JavaScript 动态加载主机 Web 的样式表。如果您在页面上使用 jQuery,则可以使用以下 JavaScript 块将主机 Web 的样式表注入到您的页面上。

(function () {
    // Retrieve the host web's URL from the query string
    var scriptbase = $.queryString('SPHostUrl') + '/_layouts/15/';

    // Create a <link> tag for the style sheet
    var $doclink = $('link').attr('rel', 'stylesheet');
    // The style sheet is loaded through an ASP.NET HTTP handler (defaultcss.ashx)
    $doclink.attr('href', scriptbase + 'defaultcss.ashx');

    // Add the style sheet link to the 
    $('head').append($doclink);
})();

如果不行的话你还可以看看微软的文章 如何:在 SharePoint 应用程序中使用 SharePoint 网站的样式表 举个不需要 jQuery 的例子。

许可以下: CC-BY-SA归因
scroll top