I have a script that I load in the external javascript attribute of a screen. It has one function named setVisible.
I would like to call this script as soon as the screen is loaded so I tried the onload event for the screen, but that seems to be triggered before the external javascript is fetched which means that I get an onload error: setVisible is not defined
Is it possible to call a script at onready time (after the external script is loaded) rather than at onload time (before the external script is loaded) ?
I know it will work at onload time if I have it saved load it into custom/js directory, but that means the script is sent to every program that get's run, even though it is only required/run in one program.
thanks & regards
Tony C
running script with onload
-
- Profound User
- Posts: 67
- Joined: Thu Jul 29, 2010 1:25 am
- First Name: Tony
- Last Name: Cusack
- Company Name: Welding Industries
- City: Adelaide
- State / Province: Outside Canada/USA
- Zip / Postal Code: 5139
- Country: Australia
- Location: Adelaide, South Australia
- Contact:
- Brian
- Profound Logic Staff Member
- Posts: 286
- Joined: Thu Apr 14, 2011 10:23 am
- First Name: Brian
- Last Name: May
- Company Name: Profound Logic Software
- Contact:
Re: running script with onload
In general, your javascript files are loaded asynchronously. There is no guarantee that the file will be loaded in time for onload.
One of the easiest ways to get around this is to actually include the the js file on the screen before this one if possible. The browser will keep the function available after you load the screen that needs the function. If this is not feasible, I can try to assist you in setting up something more complicated.
One of the easiest ways to get around this is to actually include the the js file on the screen before this one if possible. The browser will keep the function available after you load the screen that needs the function. If this is not feasible, I can try to assist you in setting up something more complicated.
-
- Profound User
- Posts: 67
- Joined: Thu Jul 29, 2010 1:25 am
- First Name: Tony
- Last Name: Cusack
- Company Name: Welding Industries
- City: Adelaide
- State / Province: Outside Canada/USA
- Zip / Postal Code: 5139
- Country: Australia
- Location: Adelaide, South Australia
- Contact:
Re: running script with onload
Thanks Brian,
I changed to design to have a screen preceding the filter screen & loaded my js there. This solves the problem.
I changed to design to have a screen preceding the filter screen & loaded my js there. This solves the problem.
-
- Profound User
- Posts: 72
- Joined: Fri Oct 01, 2010 5:07 pm
- First Name: Bryan
- Last Name: Leaman
- Company Name: InVue Security
- Phone: 704-752-6513 x221
- Address 1: 15015 Lancaster Hwy
- City: Charlotte
- State / Province: North Carolina
- Zip / Postal Code: 28277
- Contact:
Re: running script with onload
It'd be great to have an "onready" event or something that would get fired AFTER external scripts have been loaded.
What I've done is create onload event handlers like this:
It's ***, but works, especially since I can't format it nicely in the onload even box.
--Bryan
What I've done is create onload event handlers like this:
Code: Select all
function tryInit() {
if (typeof(InitFunction)!='undefined') {
InitFunction(); // defined in an external javascript file
} else {
setTimeout( 'tryInit()', 300)
}
}
tryInit();
--Bryan
Who is online
Users browsing this forum: No registered users and 0 guests