Forum Discussion
Extension JS works in debug but not in prod
- 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
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
- homolworksNov 25, 2024Copper Contributor
Yes, this appears to have done the trick. The CSS selector did what my JS was failing to do. Thank you so much!