From 434838ab7e46495169cdc82a7378155b34c65479 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Thu, 27 Oct 2022 14:32:54 +0000 Subject: [PATCH] fhemweb.js: better copy to clipboard (Forum #129858) git-svn-id: https://svn.fhem.de/fhem/trunk@26602 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/www/pgm2/fhemweb.js | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/fhem/www/pgm2/fhemweb.js b/fhem/www/pgm2/fhemweb.js index 1c6cfd012..d79263885 100644 --- a/fhem/www/pgm2/fhemweb.js +++ b/fhem/www/pgm2/fhemweb.js @@ -1007,15 +1007,36 @@ FW_detLink() return; if(m[1] == "forumCopy") { - if(!navigator.clipboard) - return FW_okDialog("Sorry, not supported by this browser"); FW_cmd(FW_root+"?cmd=list -r -i "+m[2]+"&XHR=1", function(data) { - navigator.clipboard.writeText('[code]'+data+'[/code]').then( - function(){ - FW_okDialog('"forum ready" definition copied to the clipboard.') }, - function(err) { FW_okDialog('Could not copy text: ', err)} - ) - }) + data = '[code]'+data+'[/code]'; + var okTxt = '"forum ready" definition copied to the clipboard.'; + var errTxt = 'Could not copy the text: '; + var ok; + if(navigator.clipboard) { + navigator.clipboard.writeText(data).then( + function(){ FW_okDialog(okTxt) }, + function(err){ FW_okDialog(errTxt+err) }); + + } else { + var ta = document.createElement("textarea"); + ta.value = data; + ta.style.top = ta.style.left = "0"; + ta.style.position = "fixed"; + document.body.appendChild(ta); + ta.focus(); + ta.select(); + try { + if(document.execCommand('copy')) + FW_okDialog(okTxt); + else + FW_okDialog(errTxt); + } catch (err) { + log('Copy:'+err); + FW_okDialog(errTxt+err); + } + document.body.removeChild(ta); + } + }); } else if(m[1] == "rename") { FW_renameDevice(m[2]);