クリップボードへの転送
Posted feedbacks - JavaScript
"hogehoge" をクリップボードに転送。 Firefox3で確認。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | function copyToClipboard (copytext) {
const supstr = Components.classes["@mozilla.org/supports-string;1"].
createInstance(Components.interfaces.nsISupportsString);
const transferable = Components.classes["@mozilla.org/widget/transferable;1"].
createInstance(Components.interfaces.nsITransferable);
const iClipboard = Components.interfaces.nsIClipboard;
const clipboard = Components.classes["@mozilla.org/widget/clipboard;1"].getService(iClipboard);
supstr.data = copytext;
transferable.addDataFlavor("text/unicode");
transferable.setTransferData("text/unicode", supstr, copytext.length * 2);
return clipboard.setData(transferable, null, iClipboard.kGlobalClipboard);
}
copyToClipboard('hogehoge');
|



mattsan
#6644()
Rating6/8=0.75
クリップボード(や同等の機能)へテキストを転送するプログラムをお願いします。 また可能でしたらクリップボードのデータを取り出すプログラムもお願いします。
システムに依存する内容ですが、応用範囲が広いと思いましたので出題させてもらいました。
[ reply ]