Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

Upload file

Post Reply
cples
Posts: 8
Joined: Thu Apr 20, 2023 3:14 pm

Upload file

Post 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?
User avatar
salvadordf
Posts: 4056
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Upload file

Post 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.
cples
Posts: 8
Joined: Thu Apr 20, 2023 3:14 pm

Re: Upload file

Post 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?
Last edited by cples on Mon Apr 24, 2023 10:56 am, edited 4 times in total.
User avatar
salvadordf
Posts: 4056
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Upload file

Post 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
cples
Posts: 8
Joined: Thu Apr 20, 2023 3:14 pm

Re: Upload file

Post by cples »

Thank you, I'll try
cples
Posts: 8
Joined: Thu Apr 20, 2023 3:14 pm

Re: Upload file

Post 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);
Post Reply