![]() |
|
call JS from Delphi code - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Atozed Software (https://www.atozed.com/forums/forum-1.html) +--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html) +---- Forum: English (https://www.atozed.com/forums/forum-16.html) +----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html) +----- Thread: call JS from Delphi code (/thread-4661.html) |
call JS from Delphi code - iwuser - 11-11-2024 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. RE: call JS from Delphi code - fishingtested - 11-11-2024 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. RE: call JS from Delphi code - RenSword - 11-13-2024 (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? 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'); RE: call JS from Delphi code - iwuser - 11-13-2024 (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? 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! RE: call JS from Delphi code - iwuser - 11-19-2024 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. Ha! Just discovered that form's own ExecuteJS does work in such cases, great! |