Execute function at future date/time even if user is not using app

More a Javascript question than an Ionic-specific one but any ideas as to how I can set a function up so that it runs in a week’s time whether or not the app is in use at that time? So far I have thought of using window.setTimeout but that is obviously dependent on the current browser session. I’ve also thought of a while loop but it seems like that would be a messy solution.

Any help would be welcome. Thank you.