0

i searched this problem in stackoverflow but i didn't find a good solution, so, my problem is that in my extension, jQuery doesn't work...

extension.xul:

<overlay xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'>
    <script type='application/javascript' src='chrome://extension/content/jQuery.js'></script>
    <script type='application/javascript' src='chrome://extension/content/extension.js'></script>

    <toolbar id="nav-bar">
        <toolbarbutton id="ext-toolbarbutton" label="extension" tooltiptext="extension" type="menu">
            <menupopup>
                <menuitem id="ext-toolbar-state" type="checkbox" label="Activate" accesskey="A" checked="true" oncommand="ext.disabled"/>
            </menupopup>
        </toolbarbutton>
    </toolbar>
</overlay>

extension.js

function Ext(state){
    this.state = state;
}

Ext.prototype.enable = function(){
    $("#ext-toolbar-state").attr("oncommand", "ext.disabled");
}

Ext.prototype.disabled = function(){
    $("#ext-toolbar-state").attr("oncommand", "ext.enable");
}

var ext = new Ext("enable");

thanks !

Filipe Silva
  • 21,189
  • 5
  • 53
  • 68
Freddy
  • 137
  • 8
  • 1
    What is the purpose of this extension ? I personally use "jQuerify" extension [firebug extension] to load jquery in any page .. – Stphane Oct 17 '13 at 14:36
  • This extension is a userscript but I do not want to use greasemonkey and I don't know jquerify, where can I find documentation ? – Freddy Oct 17 '13 at 14:41
  • [Firequery extension documentation](https://addons.mozilla.org/fr/firefox/addon/firequery/?src=search) – Stphane Oct 17 '13 at 14:43
  • ok but i have to use jquery in my class without jquerify – Freddy Oct 17 '13 at 14:50
  • Have you any constraints due to your class environment that would prevent you from including jquery the standard way ? `:/` – Stphane Oct 17 '13 at 14:54
  • i don't think, my extension and my userscript use jQuery thus i wanted to include jQuery in this way... i am not sure that jquerify is the standard way, if an user use my extension, it will also have jquerify... – Freddy Oct 17 '13 at 15:13
  • By saying standard way I meant by putting a reference to the script inside the content of the page loaded – Stphane Oct 17 '13 at 15:24
  • you say that I hurt included jquery ?! so what the great way to include jQuery for use in my extension and my userscript ? – Freddy Oct 17 '13 at 15:30
  • I don't know about extensions in Firefox, I must have misunderstood something – Stphane Oct 17 '13 at 15:46
  • 2
    Using jquery in `XUL` does not work a lot of stuff, can clash with other add-on doing the same but with different jquery versions (therefore you'll need `.noConflict()` at least; your `ext` name might also clash with other add-ons using the same, obvious name) and is a waste of resources (load time, memory) anyway. What's wrong with just using the regular DOM APIs and avoid all that? `.getElementById()` `.setAttribute()`, etc will work just fine... – nmaier Oct 19 '13 at 01:50
  • Possible duplicate of [How to use jQuery in Firefox Extension](http://stackoverflow.com/questions/491490/how-to-use-jquery-in-firefox-extension) – Paul Sweatte Dec 02 '15 at 12:43

0 Answers0