2017-02-25 21 views
0

の取得は、私はJSでクリップボードのテキストを取得しようとするものである:UWP:ここでクリップボードのテキスト

function getClipboard() { 
    var content = Windows.ApplicationModel.DataTransfer.Clipboard.getContent(); 
    if (content.contains(Windows.System.string)) { 
     var text = content.getTextAsync(Windows.System.string); 
     $('section#show-clipboard #textarea').text(text); 
    } else {}; 
}; 

私はClipboard.getContent()DataPackageView.getTextAsync(Windows.System.String)メソッドを使用しています。

興味深いのは、それは私がクリップボードにコピーどのくらいのテキスト問題ではありません、それは常にcontent.contains(Windows.System.string)falseに等しいことを言うだろうとcontent.getTextAsync(Windows.System.string);

の例外が表示されますことをこれは例外です:

0x8004006a - JavaScript runtime error: Invalid clipboard format

DataPackage does not contain the specified format. Verify its presence using DataPackageView.Contains or DataPackageView.AvailableFormats. WinRT information: DataPackage does not contain the specified format. Verify its presence using DataPackageView.Contains or DataPackageView.AvailableFormats.

答えて

2

私はWindows.System.stringが間違っていると思うcontent.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)

+0

あなたは正しいと思います。少なくともDataPckageViewはif文を渡します。しかし、 'JSON.stringify(content.getTextAsync(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text))'が返すオブジェクトは '{" operation ":{}}'です。それは意味をなさない... – jonhue

+1

GetTextAsyncは非同期であり、実際のテキストではなくJavaScriptの約束を返します。実行方法については、https://docs.microsoft.com/en-us/windows/uwp/threading-async/asynchronous-programming-universal-windows-platform-apps#asynchronous-patterns-in-uwp-using-javascriptを参照してください。それ。 –

関連する問題