Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisobriensp/49d1eb63326c44796a6e627f7e2881ce to your computer and use it in GitHub Desktop.
Save chrisobriensp/49d1eb63326c44796a6e627f7e2881ce to your computer and use it in GitHub Desktop.
Adds some JS to every page as part of an SPFx Application Customizer.
export default class CobGlobalJsApplicationCustomizer
extends BaseApplicationCustomizer<ICobGlobalJsApplicationCustomizerProperties> {
private _externalJsUrl: string = "https://sharepointnutsandbolts.azurewebsites.net/scripts/SPFxGlobalScript.js";
@override
public onInit(): Promise<void> {
console.log(`CobGlobalJsApplicationCustomizer.onInit(): Entered.`);
let scriptTag: HTMLScriptElement = document.createElement("script");
scriptTag.src = this._externalJsUrl;
scriptTag.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(scriptTag);
console.log(`CobGlobalJsApplicationCustomizer.onInit(): Added script link.`);
console.log(`CobGlobalJsApplicationCustomizer.onInit(): Leaving.`);
return Promise.resolve<void>();
}
// other methods omitted..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment