Jump to content

Recommended Posts

Posted

I've already searched the forum and found several topics about it, but none of them really helped.

I have a TUniEdit and a TUniButton and I want to click on the TUniButton and paste the content from the Clipboard to the TUniEdit.

To send it to the clipboard I can do it like this
 

   UniSession.AddJS('navigator.clipboard.writeText("' + UniEdit1.text + '");');

How can I paste it ?

Posted
3 hours ago, Luciano França said:

How can I paste it ?

Hello,

It seems there might be a small misunderstanding — unlike writing to the clipboard (which can often be done programmatically), reading from the clipboard in a web application is much more restricted for security reasons.
The navigator.clipboard.readText() function requires that it be triggered by a user-initiated event (like a direct click or keypress), and even then, it doesn't always work reliably across all browsers or within embedded web apps like uniGUI.

That’s likely why the posts you found didn’t fully help — clipboard reading simply isn’t permitted in the same flexible way as clipboard writing.

If the goal is to allow the user to paste into a TUniEdit, the most consistent approach is to let them press Ctrl+V or right-click → Paste directly.
If you still want to attempt programmatic access, you’d need to wrap navigator.clipboard.readText() inside a click event handler and make sure proper permissions are granted by the browser.

Posted
1 hour ago, Sherzod said:

If you still want to attempt programmatic access

Hello.
I have this question too.


Let me explain further.

I have seen several PWA in this thread,

The PWA owner sends a one-time password via SMS via his number and then it is pasted in the password field in the PWA.

 

Regards.

Posted
2 hours ago, Sherzod said:

Hello,

It seems there might be a small misunderstanding — unlike writing to the clipboard (which can often be done programmatically), reading from the clipboard in a web application is much more restricted for security reasons.
The navigator.clipboard.readText() function requires that it be triggered by a user-initiated event (like a direct click or keypress), and even then, it doesn't always work reliably across all browsers or within embedded web apps like uniGUI.

That’s likely why the posts you found didn’t fully help — clipboard reading simply isn’t permitted in the same flexible way as clipboard writing.

If the goal is to allow the user to paste into a TUniEdit, the most consistent approach is to let them press Ctrl+V or right-click → Paste directly.
If you still want to attempt programmatic access, you’d need to wrap navigator.clipboard.readText() inside a click event handler and make sure proper permissions are granted by the browser.

And how could I do it?

Posted
48 minutes ago, Luciano França said:

And how could I do it?

For example:

procedure TMainForm.UniFormCreate(Sender: TObject);
begin
  UniButton1.JSInterface.JSAddListener('click', 'function(){navigator.clipboard.writeText("' + UniEdit1.text + '")}');
  UniButton2.JSInterface.JSAddListener('click', 'function(){navigator.clipboard.readText().then((clipText) => ('+ UniEdit2.JSName +'.setValue(clipText)))}');
end;

 

3 hours ago, Sherzod said:

and make sure proper permissions are granted by the browser

 

  • Thanks 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...