Forum Discussion

homolworks's avatar
homolworks
Copper Contributor
Nov 22, 2024
Solved

Extension JS works in debug but not in prod

I have built a very small application customizer extension that is trying to do the following: hide the author panel, including the view count, from the news.aspx page in Sharepoint Online The ap...
  • michalkornet's avatar
    Nov 24, 2024

    Hi homolworks  It is not recommended to change the predefined layout in SharePoint, but if it is really needed in your case, you can try assigning a CSS file in the Application Customizer. 

     

        //set the css file url
        const cssGlobalUrl = 'https://contoso.sharepoint.com/Styles/Main.css';
    
        //get the head element
        const element = document.getElementsByTagName('head')[0] || document.documentElement;
        // assign CSS file url to the link element
        const linkElement = document.createElement('link');
        //set CSs Version by time
        linkElement.href = `${cssGlobalUrl}`;
        linkElement.rel = 'stylesheet';
        linkElement.type = 'text/css';
    
        element.insertAdjacentElement('beforeend', linkElement)

     

    Let me know if it works in your case. In your current approach, the elements might not have been rendered yet when you check them in the code

Resources