forked from appjs/appjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Clipboard Copy
franck34 edited this page Aug 22, 2012
·
5 revisions
WARNING: IF YOUR APPLICATION DISPLAY EXTERNAL DATA AND IF YOU MISS A CROSS SIDE SCRIPTING VULNERABILITY, IMPLEMENTING THIS FEATURE CAN BE VERY DANGEROUS
First, you have to disable security when you create the window in appjs.js
var window = app.createWindow({
disableSecurity:true
});
Then, add the function below in your main js code
Clipboard = {};
Clipboard.utilities = {};
Clipboard.utilities.createTextArea = function(value) {
var txt = document.createElement('textarea');
txt.style.position = "absolute";
txt.style.left = "-100%";
if (value != null) txt.value = value;
document.body.appendChild(txt);
return txt;
};
Clipboard.copy = function(data) {
if (data == null) return;
var txt = Clipboard.utilities.createTextArea(data);
txt.select();
document.execCommand('Copy');
document.body.removeChild(txt);
};
Now you can use Clipboard.copy('sometext') (bind a button or Ctrl+C ? as you want)