Posts: 79
Threads: 23
Joined: Feb 2022
Reputation:
1
Location: Melbourne
There are many examples of the reverse, but none that gives you ability to call a JS function on a page from Pascal. Is it possible?
For instance, I want to submit a form. Which I have just dynamically created on the page.
I know that if I add some OnLoad JS somewhere and click some button synchronously, it would re-render the form, execute that OnLoad function and this can submit my form, but I'm trying to avoid reloading the form, I want the buttons to work asynchronously, so there will be no reload and any OnLoad events there would not fire.
Posts: 0
Threads: 0
Joined: Nov 2024
Reputation:
0
Yes, it is possible to interact with JavaScript from a Pascal-based environment, but it requires an interface like JavaScript/Pascal bridge or using an embedded browser (e.g., via a component like TChromium in Delphi or TWebBrowser in C++ Builder). You can call JavaScript functions from Pascal asynchronously without triggering a page reload by executing JavaScript code via the browser's scripting engine directly. This way, the form submission happens asynchronously, and the page does not reload, preventing any OnLoad events from firing.
Posts: 21
Threads: 8
Joined: Sep 2023
Reputation:
0
(11-11-2024, 07:30 AM)iwuser Wrote: There are many examples of the reverse, but none that gives you ability to call a JS function on a page from Pascal. Is it possible?
For instance, I want to submit a form. Which I have just dynamically created on the page.
I know that if I add some OnLoad JS somewhere and click some button synchronously, it would re-render the form, execute that OnLoad function and this can submit my form, but I'm trying to avoid reloading the form, I want the buttons to work asynchronously, so there will be no reload and any OnLoad events there would not fire.
TIWButton should have a OnAsyncClick event.
To call JS function from Pascal, this should work
WebApplication.ExecuteJS('javascript goes here');
or
WebApplication.CallbackResponse.AddJavaScriptToExecute('javascript goes here');
Posts: 79
Threads: 23
Joined: Feb 2022
Reputation:
1
Location: Melbourne
11-13-2024, 05:37 AM
(This post was last modified: 11-13-2024, 05:54 AM by iwuser.)
(11-13-2024, 02:35 AM)RenSword Wrote: (11-11-2024, 07:30 AM)iwuser Wrote: There are many examples of the reverse, but none that gives you ability to call a JS function on a page from Pascal. Is it possible?
For instance, I want to submit a form. Which I have just dynamically created on the page.
I know that if I add some OnLoad JS somewhere and click some button synchronously, it would re-render the form, execute that OnLoad function and this can submit my form, but I'm trying to avoid reloading the form, I want the buttons to work asynchronously, so there will be no reload and any OnLoad events there would not fire.
TIWButton should have a OnAsyncClick event.
To call JS function from Pascal, this should work
WebApplication.ExecuteJS('javascript goes here');
or
WebApplication.CallbackResponse.AddJavaScriptToExecute('javascript goes here');
Ok, great, many thanks, trying it now. " WebApplication.ExecuteJS" with the submit part did not work for me, probably because IW constructs the FORM in the same Ajax call. I probably need to create the form from the same script instead, experimenting now...
(11-11-2024, 09:26 AM)fishingtested Wrote: Yes, it is possible to interact with JavaScript from a Pascal-based environment, but it requires an interface like JavaScript/Pascal bridge or using an embedded browser (e.g., via a component like TChromium in Delphi or TWebBrowser in C++ Builder). You can call JavaScript functions from Pascal asynchronously without triggering a page reload by executing JavaScript code via the browser's scripting engine directly. This way, the form submission happens asynchronously, and the page does not reload, preventing any OnLoad events from firing.
Thanks! But as I'm doing it in the context of IW, it's actually easier - see the other response I have received.
Fantastic, if I do the whole thing in the same call - create form and submit it, it works perfectly, thanks again!
Posts: 79
Threads: 23
Joined: Feb 2022
Reputation:
1
Location: Melbourne
11-19-2024, 01:39 AM
(This post was last modified: 11-19-2024, 02:05 AM by iwuser.)
Unfortunately, WebApplication.ExecuteJS is not doing anything, if called during OnCreate of the form.
Even if I just call WebApplication.ExecuteJS('alert(...
It works fine on either Sync or Async clicks, for instance.
Is this a bug? Does it work for anyone on any earlier IW versions?
(11-19-2024, 01:39 AM)iwuser Wrote: Unfortunately, WebApplication.ExecuteJS is not doing anything, if called during OnCreate of the form.
Even if I just call WebApplication.ExecuteJS('alert(...
It works fine on either Sync or Async clicks, for instance.
Is this a bug? Does it work for anyone on any earlier IW versions?
Ha! Just discovered that form's own ExecuteJS does work in such cases, great!
|