diff --git a/package.json b/package.json index 3b7588d..1a3c1c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fwdekker/template", - "version": "0.0.26", + "version": "0.0.27", "description": "The base template for pages on fwdekker.com.", "author": "Felix W. Dekker (https://fwdekker.com)", "license": "MIT", diff --git a/src/main/js/Template.js b/src/main/js/Template.js index 4331732..a5cb0bf 100644 --- a/src/main/js/Template.js +++ b/src/main/js/Template.js @@ -27,11 +27,17 @@ export const $ = q => document.querySelector(q); /** * Runs the given function once the page is loaded. * - * This function can be used multiple times. It does not overwrite existing callbacks for the page load event. + * This function can be used multiple times. It does not overwrite existing callbacks for the page load event. If the + * page has already loaded when this function is invoked, `fun` is invoked immediately inside this function. * * @param fun {function(...*): *} the function to run */ export const doAfterLoad = function (fun) { + if (document.readyState === "complete") { + fun(); + return; + } + const oldOnLoad = window.onload || (() => { });