Forum Moderators: open

Message Too Old, No Replies

referencing chrome in firefox

are there any XUL extension developers in here?

         

httpwebwitch

1:23 pm on Dec 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm building a FF extension. To start, I've got some code borrowed and adapted from here:

[developer.mozilla.org...]

what it does is add an event listener to "DOMContentLoaded" - so when a page is loaded in the browser, it executes the "onPageLoad()" function.

in my toolbar XUL, I have this element:


<textbox id="xultextbox" value="blank on purpose" readonly="true"/>

so, the following code should write a variable into the textbox


onPageLoad: function(aEvent) {
var doc = aEvent.originalTarget; // doc is document that triggered "onload" event
// do something with the loaded page.
if(doc.location.href.search("myapp.com/mypage.php") > -1){
alert(myvariable); // this works
document.getElementById('xultextbox').value = myvariable // this doesn't work
}
}

the problem here is scope. "onPageLoad" is an event happening in the _content - that is, the web page. so when I reference "document.getElementById()" within the event, it's looking for my XUL textbox on the page, which ain't gonna be successful.

I need to know: how do I send that variable from the page into my toolbar?

Fotiman

2:09 pm on Dec 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Instead of this:
document.getElementById('xultextbox').value = myvariable // this doesn't work

Don't you want this?
doc.getElementById('xultextbox').value = myvariable // this doesn't work

Since doc holds the document that triggered the event?