Hi, i have included most of my js using the index.html and my app works like XDataMusicWeb, which most pages/forms is only a <div> that to be load into the main form.
my question is that , if i have some JS functions that is only specific to the particular pages and forms , how do i dynamically load the JS , during , onCreate or on before show/initialize of the new page ?
can u provide me some sample to learn, thanks.
You can programmatically create a script element with
var
script: TJSHTMLScriptElement;
begin
script := TJSHTMLScriptElement(document.createElement('script'));
// config your script element here
document.head.appendChild(script);
end;
and set what you need in this script element.
I want to try this code, i get " undeclared identifier TJSHTMLScriptElement" error in IDE. And i get "ERROR
Uncaught InvalidCharacterError: Failed to execute 'createElement' on 'Document': The tag name provided " error on browser.
I have lastest version.
Did you add the unit web to your uses list?
You can find the definition for TJSHTMLScriptElement in web.pas
The moment that the script is loaded will depend on the moment where you call the code
var
script: TJSHTMLScriptElement;
begin
script := TJSHTMLScriptElement(document.createElement('script'));
// config your script element here
document.head.appendChild(script);
end;
If you invoke this code from a button click, it will be executed after your page has already loaded for example.