画像をキャプチャできます。テキストをキャプチャする方法を理解しようとしています。セキュリティ上の理由からないと思いますが、確認したかったのです。
また、このようなもののリファレンスはありますか? window.Clipboard
object は v8 エンジンの一部ではなく、chrome ブラウザーの一部であり、公式ドキュメントが見つかりません。
画像をキャプチャできます。テキストをキャプチャする方法を理解しようとしています。セキュリティ上の理由からないと思いますが、確認したかったのです。
また、このようなもののリファレンスはありますか? window.Clipboard
object は v8 エンジンの一部ではなく、chrome ブラウザーの一部であり、公式ドキュメントが見つかりません。
リンクしたコードにはpasteHandler
、次の関数があります。
// Get the items from the clipboard
var items = e.clipboardData.items;
if (items) {
// Loop through all items, looking for any kind of image
for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf("image") !== -1) {
// We need to represent the image as a file,
var blob = items[i].getAsFile();
// and use a URL or webkitURL (whichever is available to the browser)
// to create a temporary URL to the object
var URLObj = window.URL || window.webkitURL;
var source = URLObj.createObjectURL(blob);
// The URL can then be used as the source of an image
createImage(source);
}
}
}
Chrome 開発者フレームは、items[i] がDataTransferItem
(参照)であることを教えてくれます
リファレンス ページには、kind
プロパティとgetAsString()
メソッドが表示されます。後者は、テキストをパラメーターとして受け取るコールバック関数が必要なようです。したがって、上記のスクリプトを使用してテキスト値を処理するには、リンクしたセクションを次のように変更します。
// Get the items from the clipboard
var items = e.clipboardData.items;
if (items) {
// Loop through all items, looking for any kind of image
for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf("image") !== -1) {
// We need to represent the image as a file,
var blob = items[i].getAsFile();
// and use a URL or webkitURL (whichever is available to the browser)
// to create a temporary URL to the object
var URLObj = window.URL || window.webkitURL;
var source = URLObj.createObjectURL(blob);
// The URL can then be used as the source of an image
createImage(source);
}
if (items[i].kind === "string"){
items[i].getAsString(function(s) {
alert(s);
});
}
}
}