Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7860827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:27:16+00:00 2026-06-02T22:27:16+00:00

I am trying to create an add-on through Mozilla Add-On Builder. What I need

  • 0

I am trying to create an add-on through Mozilla Add-On Builder. What I need to know is how to get the URL of a left clicked link in the active tab through the add-on and open it in a new tab.

I know this process involved adding an eventlistener through a page-mod and then using the tabs module, however I can’t seem to get the syntax correct.

Edit: (This is what I have so far)

var Widget = require("widget").Widget;
var tabs = require('tabs');
var pageMod = require("page-mod");

exports.main = function() {


    pageMod.PageMod({
    include: '*',
    contentScriptWhen: 'ready',
    contentScript: "window.addEventListener('click', function(event) { self.port.emit( 'click',event.target.toString() )},false)",
    onAttach: function(worker) {
        worker.port.on("click", function(urlClicked) {
            tabs.open(urlClicked);

        });
     }

    }); 

};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:27:17+00:00Added an answer on June 2, 2026 at 10:27 pm

    The code you have there is mostly correct and works for me. There are two issues with your content script code however:

    • It needs to call event.preventDefault() to prevent the browser from following the link. Otherwise the linked page will be loaded both in the current tab and the new tab opened by your extension.
    • It doesn’t check whether event.target is actually a link. It could be a child node of the link or it might not be a link at all.

    Altogether, your content script should look like this:

    window.addEventListener("click", function(event)
    {
      var link = event.target;
      while (link && link.localName != "a")
        link = link.parentNode;
    
      if (link)
      {
        self.port.emit("click", link.href);
        event.preventDefault();
      }
    }, false);
    

    For a non-trivial content script like this, you shouldn’t use contentScript parameter but rather put it into its own file in the data/ directory. You can then use contentScriptFile parameter when constructing the panel:

    contentScriptFile: require("self").data.url("contentScript.js"),
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a simulation for our web Portal and need to add
I was following a railscast trying to create a add link to add a
I am trying to create an add-in by using the article below http://blogs.microsoft.co.il/blogs/shair/archive/2008/07/28/how-to-create-sql-server-management-studio-addin.aspx I
I'm trying to create a simple Add-On for SQL Server 2008; it is simply
I am trying to create a Visual Studio 2008 add in, so I have
I'm trying to create a player who can add and remove items from their
I'm trying to create a new contact and add it to the AddressBook but
I'm trying to create an Outlook 2010 Add-in with Visual Studio, and I'm having
I'm trying to create an Outlook 2010 Add-in with Visual Studio. Is it possible
I am trying to create a simple ajax grid that allows me to add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.