I have a script to give me my animated backgrounds and this works wonderful already, but I wonder if there is a way to call a JS function I add by script already but until now only use inside my script. I try to find a nice way to detect on which dash and tab I am right now and thus wanted to see if I can pass on these information with a function call on page load of any tab or dash change.
#Any idea how to call a JS function I added via custom .js resource on load of a lovelace page?
1 messages · Page 1 of 1 (latest)
Isn't that information just in the URL?
It is, but the script loads once on logging into HA and then only if I decided to set some intervals or similar in there. I try to run it or a part of it by trigger from lovelace code. This would make it easier to detect a switch from tab to tab because I can directly call the function with the new information. I am quite sure that It's somehow possible to monitor the "window.location.pathname" or similar and wait for a change there. But a) I have no idea how and b) the call from tab yaml code directly would be more efficient.
Currently I have a 180 sec interval set which calls the main function and this one checks for a specific tab name inside "window.location.pathname". So if I wait worst case 180 sec it does switch to the animation I want to have on the specific tab, but instantaneous would be cooler.
If you wanna laugh at my sorry JS skills: https://github.com/dreimer1986/yourname_card_mod/blob/master/www/styles.js this is my script.