1

Currently I'm making an add-in that can copy various things from websites and paste them directly into the body of the email. Normally when I CTRL-C a hyperlink and CTRL-V into the body of the email, it shows up as a hyperlink (blue-underlined text). But if I paste the hyperlink through my add-in, it pastes the link as text only, the link gets removed.

Here is what I'm using for getting the data from the clipboard:

 var url = window.clipboardData.getData("Text");
 Office.context.mailbox.item.body.setSelectedDataAsync(url);

I'm thinking the problem is in the:

var url = window.clipboardData.getData("Text");

because it just takes the hyperlink in the clipboard and just pastes the "Text" version of it.There might also be some security issues which might be blocking pasting the hyperlink through the add-in.

I've also tried using:

var url = window.clipboardData.getData("URL");

But it just pastes a value of "null" in the body. I know these getData methods have been deprecated as of Microsoft Edge, but as I'm aware they should still work for all Internet Explorers.

Is there any other method I'm not aware of that can get the hyperlink from the clipboard and paste it as a hyperlink and not just the name/text part of it? Thanks!

gogo
  • 113
  • 2
  • 6

1 Answers1

0

The problem is not pasting the link into Outlook - the problem is getting it from the clipboard in the first place. clipboardData.getData("URL") won't work, and you can verify that in a normal IE window.

Getting HTML from the clipboard is tricky in IE. There are solutions discussed here: Get html from clipboard in javascript

Community
  • 1
  • 1
Michael Saunders
  • 2,662
  • 1
  • 12
  • 21
  • 1
    Thanks for the link. For now I'm using a temporary solution with the code: `var url = window.clipboardData.getData("Text");` `Office.context.mailbox.item.setSelectedDataAsync('' + url + '', { coercionType: "html" });` – gogo Aug 15 '16 at 14:20