# Avoid popup blocker

**URL:** <https://discourse.mozilla.org/t/avoid-popup-blocker/31549>\
**Category:** Development\
**Created:** [September 6, 2018, 3:04pm UTC](https://discourse.mozilla.org/t/avoid-popup-blocker/31549 "2018-09-06T15:04:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chilly\_bang](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/chilly_bang/32/24174_2.png) [@chilly\_bang](https://discourse.mozilla.org/u/chilly_bang)\
**Post date:** [September 6, 2018, 3:04pm UTC](https://discourse.mozilla.org/t/avoid-popup-blocker/31549/1 "2018-09-06T15:04:44Z")

</div>

I’m trying to port my Chrome extension for Firefox. It opens after clicking on the addon button in the addon bar a new tab with an address `http://example.com#url=http://url-of-the-current-page.com`.

The code for this is `void(window.open('http://example.com#url='+window.location.href,'_blank'));`.

This code is triggered by background script looking like `chrome.browserAction.onClicked.addListener(function(tab) { chrome.tabs.executeScript(tab.id, {file: "code.js"}) });`.

In Chrome this works like a charm. In Firefox it triggers the popup blocker with an alert `Firefox prevented this site from opening a popup window`.

How could i avoid popup blocker triggering and just immediately open new tab with my url?

---

<div class="post-metadata">

**Author:** ![NilkasG](https://avatars.discourse-cdn.com/v4/letter/n/0ea827/32.png) [@NilkasG](https://discourse.mozilla.org/u/NilkasG)\
**Post date:** [September 6, 2018, 3:13pm UTC](https://discourse.mozilla.org/t/avoid-popup-blocker/31549/2 "2018-09-06T15:13:48Z")

</div>

Just use the proper APIs for this:

```auto
chrome.browserAction.onClicked.addListener(tab => {
    chrome.tabs.create({ url: tab.url, });
});

```

---

<div class="post-metadata">

**Author:** ![chilly\_bang](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/chilly_bang/32/24174_2.png) [@chilly\_bang](https://discourse.mozilla.org/u/chilly_bang)\
**Post date:** [September 6, 2018, 3:30pm UTC](https://discourse.mozilla.org/t/avoid-popup-blocker/31549/3 "2018-09-06T15:30:47Z")

</div>

thank you for quick reply! maybe i use it wrong, but your code just opens a current url in the new tab… But i need that it executes the code from the file code.js…

Could you please explain how i properly use your code? This is my first approach to FF addons:)

---

<div class="post-metadata">

**Author:** ![NilkasG](https://avatars.discourse-cdn.com/v4/letter/n/0ea827/32.png) [@NilkasG](https://discourse.mozilla.org/u/NilkasG)\
**Post date:** [September 6, 2018, 3:36pm UTC](https://discourse.mozilla.org/t/avoid-popup-blocker/31549/4 "2018-09-06T15:36:28Z")

</div>

Oh, yeah, right. You’d want to prepend the `'http://example.com#url='` to `tab.url`. And you should probably call `encodeURIComponent` on it as well:

```auto
chrome.tabs.create({ url: 'http://example.com#url='+ encodeURIComponent(tab.url), });

```

---

<div class="post-metadata">

**Author:** ![chilly\_bang](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/chilly_bang/32/24174_2.png) [@chilly\_bang](https://discourse.mozilla.org/u/chilly_bang)\
**Post date:** [September 6, 2018, 3:56pm UTC](https://discourse.mozilla.org/t/avoid-popup-blocker/31549/5 "2018-09-06T15:56:52Z")

</div>

> [@NilkasG](#):
>
> ({ url: '[http://example.com#url='+](http://example.com#url='+) encodeURIComponent(tab.url), });

YEah! this works like expected! Nice, thank you!
