0

I have a web page that makes an Ajax call to my server (using javascript) that returns html formatted text that I want to insert into the local clipboard so that the user can then paste (ctrl-v) it into either their email or calendar application. The text that I am copying to the clipboard will not be displayed on the user interface. Using clipboard.js I have successfully managed to get the html into the clipboard but when I paste it to either outlook or gmail I see the html source code rather than the formatted code. I would like this to work on as many browsers as possible (including mobile).

Below is a simplified version of the javascript that I am currently using:

    $.ajax({
        type: "Get",
        url: "/GetFormattedHtml",
        data: JSON.stringify({ "user": user }),
        contentType: "application/json; charset=utf-8",
        success: function (res) {
            var clipboard = new Clipboard(obj, {
                text: function () {
                    return "<i>" + res.MessageStatusText + "</i>";
                }
            });
            clipboard.on('success', function (e) {
                console.log(e);
            });
            clipboard.on('error', function (e) {
                console.log(e);
            });
            //clipboard.destroy();
        }
    });
Zeno Rocha
  • 3,226
  • 1
  • 23
  • 27
Simon Shaw
  • 175
  • 1
  • 10
  • What do you mean by "formatted"? As in rendered? – mostruash Mar 02 '16 at 15:10
  • It appears that with most browser's clipboard apis, headers can be set on the data you're adding to the clipboard, but I haven't been able to find any documentation for clipboard.js regarding this. [Source](https://www.lucidchart.com/techblog/2014/12/02/definitive-guide-copying-pasting-javascript/) – shamsup Mar 02 '16 at 15:24
  • Responding to mostruash, by format I mean rendered HTML rather than HTML source – Simon Shaw Mar 02 '16 at 18:30

0 Answers0