UWP: Getting the Clipboard Text

0

Here is what I try to get the Clipboards text in js:

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 {};
};

I am using the Clipboard.getContent() and the DataPackageView.getTextAsync(Windows.System.String) Methods.

The interesting thing is that it does not matter how much text I copy to the clipboard, it will always say that content.contains(Windows.System.string) equals false and will show an exception for content.getTextAsync(Windows.System.string);

This is the exception:

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.

javascript
uwp
clipboard
asked on Stack Overflow Feb 25, 2017 by jonhue • edited Feb 25, 2017 by IInspectable

1 Answer

2

I think Windows.System.string as paramter is wrong try content.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)

answered on Stack Overflow Feb 25, 2017 by ctron

User contributions licensed under CC BY-SA 3.0