# Copy the links \<a\>

**URL:** <https://discourse.mozilla.org/t/copy-the-links-a/31707>\
**Category:** Development\
**Created:** [September 12, 2018, 11:35am UTC](https://discourse.mozilla.org/t/copy-the-links-a/31707 "2018-09-12T11:35:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KK\_Kasturi](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@KK\_Kasturi](https://discourse.mozilla.org/u/KK_Kasturi)\
**Post date:** [September 12, 2018, 11:35am UTC](https://discourse.mozilla.org/t/copy-the-links-a/31707/1 "2018-09-12T11:35:59Z")

</div>

Hi,

I have created a FF web extension with context menus.

When I select a text and right click, I see my context menu, I click it and display the selected text. Here the selected text displayed is plain text where as I would like display the styles or links in the selected text.

How can I solve this please?

browser.contextMenus.onClicked.addListener(function (info, tab) {

```
	if (info.selectionText) {

		console.log(info.selectionText);

```

}

}

Any help is much appreciated

Thanks

---

<div class="post-metadata">

**Author:** ![jscher2000](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/jscher2000/32/28202_2.png) [@jscher2000](https://discourse.mozilla.org/u/jscher2000)\
**Post date:** [September 13, 2018, 12:47am UTC](https://discourse.mozilla.org/t/copy-the-links-a/31707/2 "2018-09-13T00:47:56Z")

</div>

Hmm, Firefox 56 added info.linkText. Maybe that will help? It’s not clear whether that is applicable to a selection or can be easily combined with it.

> **[menus.OnClickData - Mozilla | MDN](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/menus/OnClickData)**
>
> Information passed to the menus.onClicked event listener when a menu item is clicked.

You may need to interrogate the selection using standard DOM methods.

---

<div class="post-metadata">

**Author:** ![KK\_Kasturi](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@KK\_Kasturi](https://discourse.mozilla.org/u/KK_Kasturi)\
**Post date:** [September 13, 2018, 10:26am UTC](https://discourse.mozilla.org/t/copy-the-links-a/31707/3 "2018-09-13T10:26:21Z")

</div>

info.linkText gives me the text of the link  
and  
info.selectedText gives me the plain text that is selected

But I would like to get the hyper links in the selected text  
I was getting the below text “Sign in to your BBC account, or Register to see Weather, Local News and more”

Where as I would like to get actual html tags as below

[Sign in](https://session.bbc.co.uk/session?userOrigin=homepage&context=homepage&ptrt=https%3A%2F%2Fwww.bbc.co.uk%2Fhome%2Fcustomise) to your BBC account, or [Register](https://session.bbc.co.uk/session?action=register&userOrigin=homepage&context=homepage&ptrt=https%3A%2F%2Fwww.bbc.co.uk%2Fhome%2Fcustomise) to see Weather, Local News and more

---

<div class="post-metadata">

**Author:** ![freaktechnik](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/freaktechnik/32/37766_2.png) [@freaktechnik](https://discourse.mozilla.org/u/freaktechnik)\
**Post date:** [September 13, 2018, 1:26pm UTC](https://discourse.mozilla.org/t/copy-the-links-a/31707/4 "2018-09-13T13:26:00Z")

</div>

You will have to get that information using a content script, listening for the `contextmenu` event and then getting the links inside the selection.
