簡體   English   中英

試圖在 SharePoint Online SPFx 中使用應用程序定制器隱藏 div

[英]Trying to hide a div with an Application Customizer in SharePoint Online SPFx

我編寫了一個運行良好的 SPFx 應用程序定制器,我可以使用它登錄到控制台。

但是,當我嘗試在 SPO 中隱藏頁面左上角的“SharePoint”鏈接時,出現以下錯誤

謝謝P

錯誤:無法創建應用程序定制器“ClientSideExtension.ApplicationCustomizer.ab3da44e-81af-4590-9bf3-b305f602265c”。 錯誤信息是'無法設置未定義的屬性(設置'顯示')'。

    Log.info(LOG_SOURCE, `Initialized ${strings.Title}`);

    let message: string = this.properties.testMessage;
    if (!message) {
      message = '(No properties were provided.)';
    }

    // Dialog.alert(`Hello from ${strings.Title}:\n\n${message}`).catch(() => {
    //   /* handle error */
    // });

    console.log('DefaultApplicationCustomizerApplicationCustomizer onInit...');

    console.log('get homeLink');
    let homeLink: any = document.getElementsByClassName('o365sx-appName');
    console.log('got homeLink');
    homeLink.style.display = "none"; 
    console.log('changed homeLink');

getElementsByClassName返回一個元素列表 你需要第一個:

let homeLink: any = document.getElementsByClassName('o365sx-appName')[0] ;

您也可以嘗試使用以下代碼:

let homeLink: any = document.getElementById("O365_SuiteBranding_container");

或者

let homeLink: any = document.querySelector("div#O365_SuiteBranding_container");

查看更多信息: 如何在多個 SharePoint 現代頁面上包含相同的 JS 和 CSS 文件?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM