leinz
leinz

Reputation: 147

Intercepting searchbar events using the Firefox add-on sdk

I am making a firefox add-on using the add-on sdk, also known as Jetpack.

What I need is to intercept events, especially pasting in the searchbar and the possibility of cancelling it due to user feedback. How can I register a listener that makes this possible?

Upvotes: 1

Views: 297

Answers (2)

jordom
jordom

Reputation: 570

  1. Use DOM Inspector add-on to find out the search bar's id.

  2. In your source code:

    var utils = require('sdk/window/utils');
    
    var doc = utils.getMostRecentWindow().document;
    var searchbar = doc.getElementById("searchbar");
    searchbar.addEventListener("change", /* your callback function here */ );
    

Upvotes: 0

Matthew Gertner
Matthew Gertner

Reputation: 4537

You should be able to check for changes to the searchbar like this (from your overlay):

var searchbar = document.getElementById("searchbar");
searchbar.addEventListener("change", function(e) { // do something // }, false);

Your handler will be called whenever the contents of the searchbar change so you can take appropriate action.

Upvotes: 1

Related Questions