views:

995

answers:

4

How do you copy the html code of a link to the clipboard and parse it as a link in Lotus Notes?

For example, in Javascript put <a href='http://www.stackoverflow.com'&gt;StackOverFlow&lt;/a&gt; into clipboard, and then parse it as a link in Lotus Notes while writing a new email. It should only show a link as StackOverFlow in new message.

I found a function window.clipboardData.setData("Text",link), but it can only copy the text into clipboard.

Any tips for me?

+1  A: 

window.clipboardData is an Internet Explorer only feature. Other browser vendors view meddling with the clipboard as a security threat and potentially really really annoying so it isn't implemented in Firefox, for example.

The only way I know to do it cross-browser is to use a Flash movie, and you can find out more about that here: http://www.jeffothy.com/weblog/clipboard-copy/

If you're happy with supporting IE only, then the way to get the full outer HTML of an element (not just the innerHTML) would be to duplicate the link into another element and get the innerHTML of that element.

The javascript looks something like this (sorry, it's untested)

var newEl = myLink.cloneNode()
var div = document.createElement('div');
div.appendChild(newEl);
var outerHTML = div.innerHTML;    // <-- this is the variable you want.
nickf
Thanks nickf ^^Only available in IE is ok.But my problem is the content I parsed is not a real link, after copy into clipboard. I need to parsed it into Louts Notes as a real link, which only shows link title and hide link address.
A: 

Thank you very much nickf ^^

I have tried your codes as following:

<a id="myLink" href="http://www.google.com"&gt;Google Site</a>
<input type="button" name="anniu1" onclick="copyUrl()" value="copy it"> 
<script language="javascript"> 
   function copyUrl()
   { 
    var newEl = myLink.cloneNode()
    var div = document.createElement('div');
    div.appendChild(newEl);
    var outerHTML = div.innerHTML;    // <-- this is the variable you want.
    window.clipboardData.setData("Text",outerHTML); 
   } 
</script>

I run it in a HTML file, but when I parse it in to Lotus Notes, it shows :

<a id="myLink" href="http://www.google.com"&gt;Google Site</a>

What I need is a real link like Google Site

Hi Huiyu, from here it sounds like an issue with Lotus Notes, which I'm not familiar with, sorry. One other thing: to share extra information like this, you should click on the "edit" link just below your question. That way, this important info won't get mixed up with the answers. Cheers.
nickf
Sorry for my stupid action. Thank you very much nickf.
+1  A: 

To create a link in a Lotus Notes email you have to:

  1. Write the Text for the link example: Stackoverflow
  2. Select the text
  3. Click Create->Hotspot->Link Hotspot...
  4. Enter the url in the Value field

This is for Notes 7. Not sure if it was Notes 8 or 8.0.2 where they added a button on the toolbar to make it easy to do this.

Hope this helps

Carlos
Thank you Carlos :) But I need create a link by parse the content from clipboard.
@Huiyu it is possible (I think) to access the windows clipboard from LotusScript - so you could write an action button.
LRE
@Carlos's approach however is the quick way of doing it. You will need to copy just the URL and paste it in the hotspot properties.
LRE
+1  A: 

@Carlos has the basic user-level way to do it but it seems you want to do this programattically. I think the most effective approach is to have an action such as "paste link" that:

  1. accesses the clipboard
  2. parses the text into a basic html fragment
  3. saves that fragment to disk
  4. imports that html into the rich text field

here's an example on how to get to the clipboard.

To import the link into notes, build a rudimentary HTML file from your action, along the lines of:

<html><body>
<a id="myLink" href="http://www.google.com"&gt;Google Site</a>
</body></html>

save it and then import it using code like:

dim ws as New NotesUIWorkspace
dim d as NotesUIDocument
set d = ws.currentDocument

call d.import( "HTML File", "c:\foo.html" )

(assuming you saved your file as "c:\foo.html").

Depending on what exactly you are trying to achieve and what you're most comfortable with, you may want to compose the HTML outside of Notes and just have the action do the import bit. If you take this approach then the need to play with the clipboard is gone.

Note the following:

  • the method `NotesUIDocument.Import()` injects the contents of the HTML file wherever the cursor is in the rich text (body) field. You need to have your cursor in the right place.
  • if you've got the cursor in a non-rich text field you will probably get an error.
  • the method `NotesUIDocument.Import()` mirrors the functionality of the menu item `File \ Import` so you don't even have to write any code in Notes if you don't want to.
LRE