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

  • Home
  • SEARCH
  • 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 870401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:28:07+00:00 2026-05-15T10:28:07+00:00

I want to trigger events from a Firefox extension, specifically click events. I’ve tried

  • 0

I want to trigger events from a Firefox extension, specifically click events. I’ve tried jQuery’s .click() as well as the whole:

 var evt = document.createEvent("HTMLEvents");
 evt.initEvent("click", true, false );
 toClick[0].dispatchEvent(evt);

This is not working for me, and I was wondering if this is even possible? (to trigger events from a Firefox extension)?

I think it may have something to do with what document I create the event on…but I’m not sure.

If so, how does one do it?

  • 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-05-15T10:28:08+00:00Added an answer on May 15, 2026 at 10:28 am

    First of all, for click events, you need to create an event object with type MouseEvents, not HTMLEvents, and use event.initMouseEvent instead of event.initEvent.

    To access the document of the current tab of Firefox from a XUL overlay, you can use the content.document property, but since you already have access to the DOM element you want to click, you can use the Node.ownerDocument property, which will refer to the top-level document object for this node.

    I have made a simple function to simulate MouseEvents:

    function triggerMouseEvent(element, eventName, userOptions) {
      var options = { // defaults
        clientX: 0, clientY: 0, button: 0,
        ctrlKey: false, altKey: false, shiftKey: false,
        metaKey: false, bubbles: true, cancelable: true
         // create event object:
      }, event = element.ownerDocument.createEvent("MouseEvents");
    
      if (!/^(?:click|mouse(?:down|up|over|move|out))$/.test(eventName)) {
        throw new Error("Only MouseEvents supported");
      }
    
      if (typeof userOptions != 'undefined'){ // set the userOptions
        for (var prop in userOptions) {
          if (userOptions.hasOwnProperty(prop))
            options[prop] = userOptions[prop];
        }
      }
      // initialize the event object
      event.initMouseEvent(eventName, options.bubbles, options.cancelable,
                           element.ownerDocument.defaultView,  options.button,
                           options.clientX, options.clientY, options.clientX,
                           options.clientY, options.ctrlKey, options.altKey,
                           options.shiftKey, options.metaKey, options.button,
                           element);
      // dispatch!
      element.dispatchEvent(event);
    }
    

    Usage:

    triggerMouseEvent(element, 'click');
    

    Check a test usage here.

    You can pass also an object as the third argument, if you want to change the values of the event object properties.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to trigger copy event from JavaScript/jQuery? I want to simulate copy
What I want to do is trigger a function from an extension/GM Script once
I have added the library shortcut.js from http://www.openjs.com/scripts/events/keyboard_shortcuts/ and tried to trigger a function
I want to trigger a long running background process (coded as a service) from
I want to trigger on click of a button this: <asp:Button runat=server ID=submit Text=Submit
I have an click function that I want to trigger outside of the function
I know that jQuery can programmatically trigger events on DOM elements that are listening
I want to replace the Backbone.Events system from some sub object with the one
Creating app with jQuery Mobile, I want a page to load data from a
Just in firefox i want to trigger an event whenever the size of an

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.