question

johnjohn-0472 avatar image
0 Votes"
johnjohn-0472 asked ·

How i can force my SPFX extension to run on the site home page only + load a javascript

I am working on a SharePoint online modern team site, and I am following these steps to inject custom CSS inside my pages @ https://tahoeninjas.blog/2018/05/08/inject-custom-css-on-sharepoint-modern-pages-using-spfx-extensions/ .. now it worked well, where i added this inside my .ts file:-

76781-code.png

now it is working well on all the pages >> but I am not sure how I can modify my SPFX to do the following:-

1) only run the extension on the home page of the site?

2) reference a custom JavaScript beside the custom css? Any advice please?

office-sharepoint-online
code.png (51.7 KiB)
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Jerryzy-MSFT avatar image
0 Votes"
Jerryzy-MSFT answered ·

Hi @johnjohn-0472 ,

  1. You can use window.location.href to check if current page is home page url.

  2. You can reference JavaScript similiar like CSS:

77022-snipaste-2021-03-12-11-17-39.png

77023-code.txt

SPFx-Application-Customizer-Global-JS-Page-Header.html

Thanks
Best Regards


If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.