MSDN Library
信息
您所需的主题如下所示。但此主题未包含在此库中。

HtmlFormatHelper Class

负责格式化您希望共享或添加至 Clipboard 的 HTML 内容。还可让您从内容中获取 HTML 片段。

语法


var htmlFormatHelper = Windows.ApplicationModel.DataTransfer.HtmlFormatHelper;

特性

[DualApiPartition()]
[MarshalingBehavior(Agile)]
[Version(0x06020000)]

成员

HtmlFormatHelper类 具有这些类型的成员:

方法

The HtmlFormatHelper 类 具有这些方法。 对于 C#、Visual Basic 和 C++,它还继承方法于Object 类.

方法说明
CreateHtmlFormat Takes a string that represents HTML content and adds the necessary headers to ensure it is formatted correctly for share and Clipboard operations.
GetStaticFragment Gets a string that represents an HTML fragment.

 

备注

有关如何使用此类的更多信息,请检验DataPackage.SetHtmlFormat。您可能还想要查看我们的主题,如何共享 HTML

示例


if (shareOperation.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.html)) {
    document.getElementById("htmlContentArea").className = "unhidden";
    
    shareOperation.data.getHtmlFormatAsync().then(function (html) {
        if (html !== null) {
            var htmlFragment = Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.getStaticFragment(htmlFormat);

            // Set the innerHTML of the ifram to the HTML fragment.
            var iFrame = document.getElementById("htmlContent");
            iFrame.style.display = "";
            iFrame.contentDocument.documentElement.innerHTML = htmlFragment;
        } 
    });

    // Loop through any images and use the resourceMap to map each image element's src.
    var images = iFrame.contentDocument.documentElement.getElementsByTagName("img");
    if (images.length > 0) {
        shareOperation.data.getResourceMapAsync().done(function (resourceMap) {
            if (resourceMap.size > 0) {
                for (var i = 0, len = images.length; i < len; i++) {
                    var streamReference = resourceMap[images[i].getAttribute("src")];
                    if (streamReference) {
                        // Call a helper function to map the image element's src to a corresponding blob URL generated from the streamReference
                        setResourceMapURL(streamReference, images[i]);
                    }
                }
            }
        });
}
//shareOperation.reportCompleted();


要求

最低支持客户端

Windows 8 [Windows 应用商店应用程序, 桌面应用程序]

最低支持服务器

Windows Server 2012 [Windows 应用商店应用程序, 桌面应用程序]

命名空间

Windows.ApplicationModel.DataTransfer
Windows::ApplicationModel::DataTransfer [C++]

元数据

Windows.winmd

 

 

显示:
© 2016 Microsoft