javascript - How can I link to an internal image within a Firefox extension? -
i'm using firefox sdk.
the following code works, @ least know working it's supposed to:
document.getelementbyid("mydiv").src="http://somesite/externalimage.jpg";
however, mozilla isn't approving version of extension, because i'm linking external image.
so have link image inside extension (i uploaded same image inside extension).
i tried following code did not work.
document.getelementbyid("mydiv").src=" + data.url("externalimage.jpg") + ";
so how link image inside extension?
first off, syntax wrong , error. should be:
document.getelementbyid("mydiv").src = data.url("externalimage.jpg");
are including data module self?
var data = require('sdk/self').data;
what context in? main sdk code has access data.url function, if in content script, won't have there, you'll need pass in value message
in main.js
// assuming pagemod here, can worker var data = require('sdk/self').data; var { pagemod } = require('sdk/page-mod'); pagemod({ include: '*', contentscriptfile: data.url('script.js'), onattach: function (worker) { worker.port.emit('link', data.url('externalimage.png'); } });
in content script, script.js:
self.port.on('link', function (url) { document.getelementbyid("mydiv").src = url; });
Comments
Post a Comment