# Opening a link in new tab from inside the firefox addon I am developing

**URL:** <https://discourse.mozilla.org/t/opening-a-link-in-new-tab-from-inside-the-firefox-addon-i-am-developing/9454>\
**Category:** Add-ons\
**Created:** [June 27, 2016, 7:18am UTC](https://discourse.mozilla.org/t/opening-a-link-in-new-tab-from-inside-the-firefox-addon-i-am-developing/9454 "2016-06-27T07:18:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MayankPratap](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mayankpratap/32/21829_2.png) [@MayankPratap](https://discourse.mozilla.org/u/MayankPratap)\
**Post date:** [June 27, 2016, 7:18am UTC](https://discourse.mozilla.org/t/opening-a-link-in-new-tab-from-inside-the-firefox-addon-i-am-developing/9454/1 "2016-06-27T07:18:56Z")

</div>

I am trying to develop a firefox addon using an API I developed. The addon shows some links but when I click that link it opens in a new window. I want them to open in a new tab.

---

<div class="post-metadata">

**Author:** ![jorgev](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jorgev](https://discourse.mozilla.org/u/jorgev)\
**Post date:** [June 28, 2016, 7:36pm UTC](https://discourse.mozilla.org/t/opening-a-link-in-new-tab-from-inside-the-firefox-addon-i-am-developing/9454/2 "2016-06-28T19:36:46Z")

</div>

It depends on the API you’re using for your add-on and how you’re adding the link.

---

<div class="post-metadata">

**Author:** ![MayankPratap](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mayankpratap/32/21829_2.png) [@MayankPratap](https://discourse.mozilla.org/u/MayankPratap)\
**Post date:** [June 29, 2016, 4:47am UTC](https://discourse.mozilla.org/t/opening-a-link-in-new-tab-from-inside-the-firefox-addon-i-am-developing/9454/3 "2016-06-29T04:47:45Z")

</div>

I am using AddOn SDK for this purpose and links are simply added using   
tag with target=’\_blank’

---

<div class="post-metadata">

**Author:** ![noitidart](https://avatars.discourse-cdn.com/v4/letter/n/9f8e36/32.png) [@noitidart](https://discourse.mozilla.org/u/noitidart)\
**Post date:** [June 29, 2016, 5:12am UTC](https://discourse.mozilla.org/t/opening-a-link-in-new-tab-from-inside-the-firefox-addon-i-am-developing/9454/4 "2016-06-29T05:12:33Z")

</div>

So these are links inside a panel? By default I think those links open within that panel correct?

I think what you’ll have to do is add a `port.emit` on your links. It should emit a message with the link to open to your `index.js`/`main.js` which will do this:

```
var tabs = require("sdk/tabs");
tabs.open("http://www.example.com");

```

My guess is that this `tabs` API opens the tab in the currently focused (meaning most recent) `navigator:browser` type window.

---

<div class="post-metadata">

**Author:** ![MayankPratap](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mayankpratap/32/21829_2.png) [@MayankPratap](https://discourse.mozilla.org/u/MayankPratap)\
**Post date:** [June 29, 2016, 9:02am UTC](https://discourse.mozilla.org/t/opening-a-link-in-new-tab-from-inside-the-firefox-addon-i-am-developing/9454/5 "2016-06-29T09:02:31Z")

</div>

It worked .

---

<div class="post-metadata">

**Author:** ![noitidart](https://avatars.discourse-cdn.com/v4/letter/n/9f8e36/32.png) [@noitidart](https://discourse.mozilla.org/u/noitidart)\
**Post date:** [June 29, 2016, 5:52pm UTC](https://discourse.mozilla.org/t/opening-a-link-in-new-tab-from-inside-the-firefox-addon-i-am-developing/9454/6 "2016-06-29T17:52:12Z")

</div>

Awesome! May you please share your code so it can help others. 🙂

---

<div class="post-metadata">

**Author:** ![MayankPratap](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mayankpratap/32/21829_2.png) [@MayankPratap](https://discourse.mozilla.org/u/MayankPratap)\
**Post date:** [June 29, 2016, 7:43pm UTC](https://discourse.mozilla.org/t/opening-a-link-in-new-tab-from-inside-the-firefox-addon-i-am-developing/9454/7 "2016-06-29T19:43:01Z")

</div>

Actually I did not do any thing to change , when I install the addon and  
open then link it opens correctly in a new tab of current active window .  
But when I do jpm run and addon opens in a new window. In that case if I  
click a link it opens in new window. So I think it depends on browser  
settings whether you open links in new tab or window. Since when we do jpm  
run our initial browser settings dont hold.
