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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:23:15+00:00 2026-05-13T13:23:15+00:00

I need it to use in my Firefox extension. I already tried window.onload event

  • 0

I need it to use in my Firefox extension.
I already tried window.onload event listener, and check if current url == old url, and it’s a good idea, but it doesn’t work when page loads PDF.

I saw hash changed function too but it works only with Firefox 3.6; I need it to work at least with Firefox 3.

So, I need an event listener that check if document.location changes.

  • 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-13T13:23:16+00:00Added an answer on May 13, 2026 at 1:23 pm

    For example, you could use:

    var mainWindow = window
        .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
        .getInterface(Components.interfaces.nsIWebNavigation)
        .QueryInterface(Components.interfaces.nsIDocShellTreeItem).rootTreeItem
        .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
        .getInterface(Components.interfaces.nsIDOMWindow);
    
    mainWindow.getBrowser().addEventListener("DOMContentLoaded",
                            your_function, false);
    

    But, the point is, you need to add the listener to the browser, not window.

    EDIT
    See https://developer.mozilla.org/En/Code_snippets/Tabbed_browser for info on accessing the browser from different contexts, as well as some other useful info.

    EDIT
    Just to add a little more detail….

    function your_function(event) {
        if (event.originalTarget instanceof HTMLDocument) {
        var doc = event.originalTarget;
            // if it's just a frame element, then return and wait for the
            // main event to fire.
            if (event.originalTarget.defaultView.frameElement)
                 return;
    
            // now you can use doc.location however you want
        }
    }
    

    Note that this will respond to pages opened in any tab, not a specific tab.


    For a specific tab, you could use something like this:

    var newTabBrowser = gBrowser.getBrowserForTab(gBrowser.addTab("http://www.google.com/"));
    newTabBrowser.addEventListener("load", function () {
        newTabBrowser.contentDocument.body.innerHTML = "<div>hello world</div>";
    }, true);
    

    The above adds a new tab and then adds a listener. However, for all tabs, you’ll need something like the following. And then add the “DOMContentLoaded” event listener on each tab when added (and removed when closed).

    You may also want to see: https://developer.mozilla.org/En/Code_snippets/Tabbed_browser#Notification_when_a_tab_is_added_or_removed and https://developer.mozilla.org/En/Code_snippets/Tabbed_browser#Getting_document_of_currently_selected_tab

    (For preservation)

    function exampleTabAdded(event) {
      var browser = gBrowser.getBrowserForTab(event.target);
      // browser is the XUL element of the browser that's been added
    }
    
    function exampleTabMoved(event) {
      var browser = gBrowser.getBrowserForTab(event.target);
      // browser is the XUL element of the browser that's been moved
    }
    
    function exampleTabRemoved(event) {
      var browser = gBrowser.getBrowserForTab(event.target);
      // browser is the XUL element of the browser that's been removed
    }
    
    // During initialisation
    var container = gBrowser.tabContainer;
    container.addEventListener("TabOpen", exampleTabAdded, false);
    container.addEventListener("TabMove", exampleTabMoved, false);
    container.addEventListener("TabClose", exampleTabRemoved, false);
    
    // When no longer needed
    container.removeEventListener("TabOpen", exampleTabAdded, false);
    container.removeEventListener("TabMove", exampleTabMoved, false);
    container.removeEventListener("TabClose", exampleTabRemoved, false);
    

    This should get you 99% of the way there.

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

Sidebar

Related Questions

I need to use jsonp-polling for IE, and xhr-polling for Firefox, so I tried
I am creating firefox extension. I need to use sockets. I need it to
I use Firefox as default browser in my computer. I need to develop the
So, I need use this event so I can navigate trought blog posts. I
I am working on a simple Firefox Extension, and I need a list of
In my Firefox extension I need to get the element boundary on which the
I'm working on a firefox extension and one of the things I need to
I need to use firefox and I need to interface my web page with
I'm writing a Firefox extension and I need to to access items in Firefox's
I am writing a Firefox extension. Right now I need to create a local

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.