Reputation: 1
Good day. I want to add jQuery in my FireFox extension I add file in .xul and use this code:
main.xul:
<overlay id="sample"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml">
<script type="application/x-javascript" src="chrome://mozillatest/content/jquery.js" />
<script type="application/x-javascript" src="chrome://mozillatest/content/main.js" />
</overlay>
main.js file:
document.addEventListener("DOMContentLoaded", function(){
$whatever = jQuery.noConflict();
if (window.$whatever) {
alert('1 check - OK 1!');
$whatever('form').on('submit', function(e) {
alert('submited');
});
});
I see alert "1 check - OK 1!" But when i navigate to some sites and press submit, i cant see alert "submited". I write extension in Chrome and it is work without problem! What i need to do?
Upvotes: 0
Views: 81
Reputation: 33162
You're loading jquery into browser.xul, which is not what you actually want. You want it in the context of pages.
I suggest you have a look at the add-on SDK instead of writing a plain XUL extension because not only will this be easier for your general use case, the SDK is also a lot more like a chrome extension. Have a look at the page-mod
SDK module.
If you still want to use plain XUL, you'd have to do the heavy lifting, that the SDK would do for you, yourself, i.e. intercepting page loads
and then using DOM methods (or jQuery, but not the regular "style") to interact with sites. But before that you'd need to wrap your head around browser.xul
and xul windows in general, overlays, <tabbrowser>
and how it relates to browser.xul
and much more.
Upvotes: 1