2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

fhemweb.js: better copy to clipboard (Forum #129858)

git-svn-id: https://svn.fhem.de/fhem/trunk@26602 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2022-10-27 14:32:54 +00:00
parent 8aa866878c
commit 434838ab7e

View File

@ -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]);