Page 1 of 1

Upload file

Posted: Sun Apr 23, 2023 9:48 am
by cples
Hi!

There is a modem settings page so that you can save or restore its configuration.
I managed to save the settings, but when uploading the configuration file to the modem, there was a problem.
Here is the code of the input field where the configuration file is selected:

Code: Select all

<input id="importCfgConfig" type="text" yltype="file" class="upload_file_input" readonly="readonly" filedesp="{'filename':'localcfgfile', 'maxlength':'5MB', 'action':'localcfg', 'filetype':'localcfg'}" value="" onclick="YLFile.SelectFile('importCfgConfig')" dvalue="">
when you click on this input field, a file selection dialog box opens.
Using JS I'm trying to call this window:

Code: Select all

Chromium1.ExecuteJavaScript('document.getElementById("importCfgConfig").click()','', 0);
but nothing happens, I assume it's because of security rules (yltype="file")
Maybe there is an option that disables security and you can open a file selection window?

Re: Upload file

Posted: Mon Apr 24, 2023 9:07 am
by salvadordf
Hi,

Try calling the YLFile.SelectFile('importCfgConfig') function instead of triggering the event.

If that's not enough consider using a browser in OSR mode. You can simulate all mouse events in that mode.

Re: Upload file

Posted: Mon Apr 24, 2023 10:39 am
by cples
calling the function YLFile.SelectFile('importCfgConfig') gives the result - "File chooser dialog can only be shown with a user activation"

The SimpleOSRBrowser demo does not open in my Delphi 7. What should I pay attention to there?

When using OSR mode, will the program window be minimized?

Re: Upload file

Posted: Mon Apr 24, 2023 12:36 pm
by salvadordf
Install Lazarus and open the /demos/Lazarus_Windows/SimpleOSRBrowser demo to see it running.

The OSR mode uses a "windowless" browser that can work even when your application is not showing it.

Read the following document and the code comments in that demo for more information.
https://www.briskbard.com/index.php?lang=en&pageid=cef

Re: Upload file

Posted: Mon Apr 24, 2023 2:18 pm
by cples
Thank you, I'll try

Re: Upload file

Posted: Sun Aug 06, 2023 1:55 pm
by cples
As a result, it was possible to solve the problem by completing the JavaScript code:

Code: Select all

const mouseClickEvents = ['mousedown', 'click', 'mouseup'];

function simulateMouseClick(element){
  mouseClickEvents.forEach(mouseEventType =>
    element.dispatchEvent(
      new MouseEvent(mouseEventType, {
        view: window,
        bubbles: true,
        cancelable: true,
        buttons: 1
      })
    )
  );
}

var element = document.getElementById("importCfgConfig"); 

simulateMouseClick(element);