Luciano França Posted March 22, 2025 Posted March 22, 2025 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 ? Quote
Sherzod Posted March 22, 2025 Posted March 22, 2025 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. Quote
Ario.Paxaz Posted March 22, 2025 Posted March 22, 2025 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. Quote
Luciano França Posted March 22, 2025 Author Posted March 22, 2025 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? Quote
Sherzod Posted March 22, 2025 Posted March 22, 2025 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 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.