Reputation: 97
I'm making a Firefox extension and trying to access a separate JavaScript file.
The directories for the files look like this:
├───defaults/ ├───content/ │ └───preferences.xul │ └───preferences.js └───locale/
Inside of preferences.xul, I include the following line:
<script type="application/javascript" src="preferences.js" />
For some reason, the JavaScript file isn't being loaded even though they're in the same location. I've made some test code that allows input on a textbox and moves that text to a listbox. If I include it in the preferences.xul file in a <script></script>
tag, it works fine but once I move it into preferences.js, it stops working.
Are there any things I can do to check what scripts are being loaded or the current directory? Thank you.
preferences.xul
<script type="application/javascript" src="preferences.js" />
<script>
//this function works fine and works like I want it to
//but I would like it to work while in preferences.js
function addItem(){
var url = document.getElementById('url').value;
//check user input
if(url){
document.getElementById('urlList').appendItem(url, url);
}
document.getElementById('url').value = '';
}
</script>
<prefpane id="idlealert-prefpane" label="&prefpane.title;">
<groupbox id="IdleAlertGroup">
<caption label="&group.label;"/>
...
<separator class="thin"/>
<row>
<vbox>
<label value="&urlList.new;" />
</vbox>
<vbox>
<textbox id="url" />
</vbox>
<vbox>
<button id="addUrl"
label="Add"
oncommand="addItem();"
/>
</vbox>
</row>
<separator class="thin"/>
<row>
<vbox>
<label value="&urlList.label;"/>
</vbox>
<listbox id="urlList"
seltype="multiple">
</listbox>
</row>
...
preferences.js
var IdleAlert = {
addItem: function(){
var url = document.getElementById('url').value;
//check user input
if(url){
document.getElementById('urlList').appendItem(url, url);
}
document.getElementById('url').value = '';
}
Upvotes: 2
Views: 67
Reputation: 41
In your chrome.manifest file you should have something like content yourextensionname content/
If so, you should be able to reference the js file like <script type="application/javascript" src="chrome://yourextensionname/content/preferences.js" />
HTH
Upvotes: 2