Skip to content
Permalink
Browse files

Create gmdevblogwebclipboard.js

  • Loading branch information...
Fritsbie committed Jul 19, 2019
1 parent 2bfb8ae commit db13a7f02344c2ebdcc0c149eaccc8ccf5da955e
Showing with 29 additions and 0 deletions.
  1. +29 −0 gmdevblogwebclipboard.js
@@ -0,0 +1,29 @@
function web_clipboard_set(text) {
var dummy = document.createElement("textarea");
// to avoid breaking orgain page when copying more words
// cant copy when adding below this code
// dummy.style.display = 'none'
document.body.appendChild(dummy);
//Be careful if you use texarea. setAttribute('value', value), which works with "input" does not work with "textarea". – Eduard
dummy.value = text;
dummy.select();
document.execCommand("copy");
document.body.removeChild(dummy);
}

function web_clipboard_get(successCallbackFunction,failedcallbackFunction) {
navigator.clipboard.readText()
.then(text => {
if (successCallbackFunction!="")
{
console.log("Clipboard content : " + text);
eval("gml_Script_"+successCallbackFunction+"(null,null,'"+text+"')");
}
})
.catch(err => {
console.log("Clipboard content fails : " + err);
if (failedcallbackFunction!=""){
eval("gml_Script_"+successCallbackFunction+"(null,null,'"+err+"')");
}
});
}

0 comments on commit db13a7f

Please sign in to comment.
You can’t perform that action at this time.