Posts: 2
Threads: 1
Joined: May 2018
Reputation:
0
Location: Europe
Hi,
How can a javascript function (from a file) automatically be started when opening a webpage?
I have already added the Javascript filename to Contentfiles and executed a function but got no result.
Greetz
Posts: 2,267
Threads: 199
Joined: Mar 2018
Reputation:
86
Location: Auckland, New Zealand
Have you checked the browser console window for errors (F12 - dev tools - Console tab)?
also, have you checked the network tab (in the same dev tools area) to see if your JavaScript file loaded correctly from server?
About your question, you can execute it like this (This is one of the ways. Actually there are several different ways to accomplish the same thing):
procedure TIWForm1.OnRender(Sender: TObject);
var
JS: string;
begin
JS := 'yourjsfunction("somestringparameter", 2, 20, "another string parameter");';
AddToInitProc(JS);
end;
Posts: 2
Threads: 1
Joined: May 2018
Reputation:
0
Location: Europe
The Javascript has loaded correctly from the server.
I didn't had the OnRender call so that is probably the cause.
Thanks for the info.