简体   繁体   中英

Trouble accessing a XUL element from JavaScript

I am having problem to access an element in my file.xul using DOM methods as given below if I do it inside the function someone.listen_request() .

But it works fine if I do it inside the progress_bar() function.

Can anyone help me in this case.

My code:

// Listening to an event from a php/html file
var someone = 
{
  listen_request: function() 
  {
    document.addEventListener("record-id", function(event) 
    {
      var node = event.target, doc = node.ownerDocument;
      var d=node.getUserData("data");
      var str=d.split(",");
      var text=str[0];
      var record_id=str[1];
      var field_id=str[2];// Working fine till here
      // **this is not working**
      document.getElementById("Telephone2").value="helo"; 
    }, false, true);
  }
}

someone.listen_request();

// Called at onLoad and onBlur..
function progress_bar(len,page_values)
{
  // **here it is working fine**
  document.getElementById("Telephone2").value="helo";
  var filed_cnt=0;
  var tot_rows=0;
  for(i=0;i<len;i++)
  {
    if(page_values[i]!="")
    { 
      filed_cnt+=parseInt(1);
    }
  }
  var compeletion= (filed_cnt/len)*100;
  var complete=Math.round(compeletion);
  document.getElementById("pbar").value=complete;
  document.getElementById("meter").value=complete;
}

Finally I did it..

The code below works for me :

mainWindow.document.getElementById("sidebar").contentDocument.getElementById("Telephone2").value="hello";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM