SetClipboardText()
Posted: Sat Jul 28, 2018 6:34 am
Need the same functionality as SetClipboardText() in Purebasic.
Thank you.
Thank you.
Code: Select all
Procedure _SetClipboardText(text.s)
! var textArea = document.createElement("textarea");
! textArea.value = v_text;
! document.body.appendChild(textArea);
! textArea.focus();
! textArea.select();
!
! try {
! document.execCommand('copy');
! } catch (err) {
! console.error('Fallback failed', err);
! }
! document.body.removeChild(textArea);
EndProcedure
Procedure SetClipboardText(text.s)
! if (!navigator.clipboard) {
! f__setclipboardtext(v_text);
! return;
! }
! navigator.clipboard.writeText(v_text);
EndProcedure
;- Demo:
Procedure Demo()
SetClipboardText(GetGadgetText(0))
EndProcedure
OpenWindow(#PB_Any, 10,10, 200,100, "SetClipboardText demo",#PB_Window_SystemMenu)
StringGadget(0,10,10,180,20,"")
ButtonGadget(1,10,40,180,20,"Copy to clipboard!")
BindGadgetEvent(1,@Demo())
WOW!poshu wrote:Ask and you shall receive!
Code: Select all
<html>
<body>
<textarea id="input">Copy me</textarea>
<button id="copy-button">Copy</button>
<script>
var input = document.getElementById("input");
var button = document.getElementById("copy-button");
button.addEventListener("click", function (event) {
event.preventDefault();
input.select();
document.execCommand("copy");
});
</script>
</body>
</html>
I can't confirm that.Dirk Geppert wrote:Unfortunately it doesn't work with my Firefox browser
I DEFINITELY did not forget about this. It was a genuinely hyper complex problem that took me 6 months of work to fix!ols3 wrote:But, create app --> Android, not OK.
SetClipboardText() doesn't work in android apk.