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 8839859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:19:55+00:00 2026-06-14T10:19:55+00:00

I have a toolbar extension that generates dynamic toolbarbutton and menuitem elements. These items

  • 0

I have a toolbar extension that generates dynamic toolbarbutton and menuitem elements. These items are typically constructed like this:

tempMenuItem = document.createElement("menuitem");
tempMenuItem.setAttribute("label",  "Some Label");
tempMenuItem.setAttribute("tooltiptext", "Some Tooltip");
tempMenuItem.setAttribute("oncommand", "myObject.someFunction()");

This code works just fine, but I get the following warning when I submit my extension to the official add-on repository:

on* attribute being set using setAttribute

Warning: To prevent vulnerabilities, event handlers (like ‘onclick’ and ‘onhover’) should always be defined using addEventListener.

How else can I set the appropriate command handler for these dynamic elements? I know this is simply a warning, but being the obsessive compulsive programmer that I am, I’d like to do things in the cleanest way possible. Is there a better way to do this?

  • 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-14T10:19:56+00:00Added an answer on June 14, 2026 at 10:19 am

    Well, you obviously use addEventListener() method as the suggestion says:

    tempMenuItem.addEventListener("command", function(event)
    {
      myObject.someFunction();
    }, false);
    

    Or somewhat shorter if you also use the Function.bind() method:

    tempMenuItem.addEventListener("command", myObject.someFunction.bind(myObject), false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a Firefox extension, and I have a toolbar button that displays an
I have a Firefox extension that adds several buttons to the nav-bar toolbar using
I have a Safari 5 extension that contains a toolbar. Whenever the current tab
I have a simple addon that adds a button to toolbar. I want this
I have a toolbar developed under older versions of Windows that is largely cut
I have written a toolbar that runs on the taskbar. Unfortunately, after it is
I have this code snippet: $(function() { $('.toolbar [id^=button]').on('click', function () { $(this) .css('background-color',
i have created an IE band object (toolbar) that is working well. however, when
I have a friefox sidebar extension. If its opened by clicking on the toolbar
I have a working firefox extension that currently consists of a button. When I

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.