0

I'm writing a firefox extension and want to solve this problem: how to know when the DOM of an iFrame is ready again after changing its content? I found this Plugin which probably will solve my problem. But I don't know how to add this in my add-builder.

My problem is here:

/************************************************************
            You must specify the path to your jquery.js file below! 
    *************************************************************/

    var jQueryPath = "/main/inc/lib/javascript/jquery.js";

the path for the jquery.js is different for every user because it's inside the firefox context, for example:

C:\Users\myname\AppData\Roaming\Mozilla\Firefox\Profiles\im0woiy2.default\flightdeck\resources\jid0-rxgsbnpfxdmtfgdq504rka9xktm-at-jetpack-privatsphaere_tool-data\jquery-1.6.4.js

so how can I add this plugin?

Community
  • 1
  • 1
Weedjo
  • 335
  • 1
  • 6
  • 17

1 Answers1

2

You use the self package of the add-on SDK:

var {data} = require("self");
var jQueryPath = data.url("jquery.js");

And you put jquery.js into the data/ directory of your add-on.

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
  • i can't use this inside of a content script, can I? `Error: uncaught exception: ReferenceError: require is not defined` – Weedjo Oct 13 '11 at 13:18
  • @Weedjo: No, you cannot and you should not. When you call `PageMod()` you should simply specify `contentScriptFile: [data.url("jquery.js"), data.url("myContentScript.js")]` - you can load more than one script file as content script. – Wladimir Palant Oct 13 '11 at 13:35
  • I knew that already, but how can I put the path into the plugin where I need it? – Weedjo Oct 13 '11 at 13:53
  • 1
    @Weedjo: Use `postMessage()` to send it from your add-on to the content script. – Wladimir Palant Oct 13 '11 at 13:59
  • @Weedjo Since the value isn't going to change, another option (cleaner than postMessage()) is to use contentScriptOptions. There is an example on this other post: http://stackoverflow.com/a/16848890/684852 – Sean Colombo May 31 '13 at 02:32
  • @SeanColombo: That's a question from 2011 - `contentScriptOptions` weren't introduced before Add-on SDK 1.8 (in June 2012). – Wladimir Palant May 31 '13 at 05:45
  • @WladimirPalant ah, cool :) well, now there here so I'm glad we got a chance to add them to this page (since this is still the top result in Google for this problem). Thanks for the original solution! – Sean Colombo May 31 '13 at 15:33