views:

27

answers:

0

HI,

I am having a Firefox plug-in with sidebar. I am having a function in the sidebar. I want to check for the readiness of the document in the main window. If the main window document is ready, the function inside the sidebar should be called.

The coding should be inside the sidebar JavaScript as the main window content will be from different domains.

My sidebar content is given below.

var mainWindow = null;
var check = 0;

function startup() {

  mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                     .getInterface(Components.interfaces.nsIWebNavigation)
                     .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
                     .rootTreeItem
                     .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                     .getInterface(Components.interfaces.nsIDOMWindow);

// Sidebar is loaded and mainwindow is ready                   
}

function fetchValues()
  {

    var urlValue = mainWindow.getBrowser().selectedBrowser.contentWindow.location.href;

    // Do Something
    // then reload the sidebar.

    reLoad();
  }

function reLoad()
{
    window.location.reload();
}

function shutdown() 
{
  //alert("Sidebar is shutting down");
}

window.addEventListener("load", startup, false);
window.addEventListener("unload", shutdown, false);

Then I tried this using

document.addEventListener("DOMContentLoaded", fetchValues, false)

But I end up in an abnormal condition. Then I used

window.addEventListener("DOMContentLoaded", function(){check=1; fetchValues()}, false);

Abnormal result too. At last I tried using

mainWindow.addEventListener("DOMContentLoaded", function(){check=1; fetchValues()}, false);

But still I haven't get any required result.

Please help me in this context.