I finally figured it out. Code below works, if anyone else runs into
this issue.
// assign the local file to a variable
var localgif = chrome.extension.getURL("/image.gif");
...
// call variable into css
pdflinks[i].style.background = 'url('+localgif+')';
On Oct 20, 3:48 pm, Jói Sigurðsson <[email protected]> wrote:
> Try pasting the URL you get from the call to chrome.extension.getURL()
> into your CSS. It will look something like
> chrome-extension://1234567890abcdef/image.gif
>
> Another way would be to use JavaScript on page load to set the
> background-image style based on the results of
> chrome.extension.getURL(), and this would probably be better (in case
> your extension ID ever changes - although it shouldn't) but I won't
> recommend it if you're not comfortable with doing some JavaScript
> programming.
>
> Cheers,
> Jói
>
>
>
> On Tue, Oct 20, 2009 at 3:44 PM, ehamiter <[email protected]> wrote:
>
> > Still can't seem to get it to work. I tried Marcos' suggestion, but
> > instead of what I expect it to do, it tries to pull the page in
> > question + /image.gif. For example, if you're on google.com and you
> > expect to see the image, after inspecting the element, you will notice
> > the img src ishttp://google.com/image.pdf, instead of chrome-
> > extension://blahblahblah/image.pdf.
>
> > I've tried chrome.extension.getURL() in the same manner but that did
> > not work. It returns what I expect, but I can't use that in a css
> > selector like url(image.gif).
>
> > I am very appreciative of the answers thus far, but I'm afraid the
> > majority of you are speaking over my head. Jói, are you saying this
> > cannot be done in a user script?
>
> > I am not sure how else to phrase my question... if you have a user
> > script extension that uses an image, and you need to reference it
> > locally with css, how do you do it? If I use an image that is not
> > local, I can do it easily. I don't understand why it isn't trivial to
> > do the former and not the latter. If you wouldn't mind, please explain
> > it with an example of something that works. I'm just an amateur coder,
> > so I have a hard time deciphering suggestions like
>
> > something.here {
> > do this
> > }
>
> > Thanks very much.
>
> > On Oct 19, 10:46 am, Erik Kay <[email protected]> wrote:
> >> 2009/10/18 Jói Sigurðsson <[email protected]>:
>
> >> > To build URLs relative to the base of the extension, use
> >> > chrome.extension.getURL(relativeUri). See API documentation at
> >> >http://chromeextensionsdocs.appspot.com/
>
> >> > Referring to resources within the extension should work fine from
> >> > extension pages (e.g. background page or a browser action drop-down)
> >> > but calling chrome.extension.getURL() will not work from a user script
> >> > since user scripts run in the context of whichever page(s) you target
> >> > them to, and those pages don't have access to the extension APIs.
>
> >> Thanks for replying Joi. Just one small clarification. User scripts
> >> have access to *almost* none of the extension APIs. One that they do
> >> have access to is chrome.extension.getURL(). Please use this within
> >> content scripts rather than trying to build up the URL manually. It
> >> will make it easier for you while you're testing.
>
> >> The others that are available are chrome.extension.connect() and
> >> chrome.extension.onConnect:http://code.google.com/chrome/extensions/extension.html
>
> >> It would be nice if we could be a bit more obvious about which are
> >> accessible and which aren't.
>
> >> Erik
>
> >> > Cheers,
> >> > Jói
>
> >> > On Sun, Oct 18, 2009 at 9:40 AM, ehamiter <[email protected]> wrote:
>
> >> >> Sorry to ask, but could you clarify a little? I tried
>
> >> >> pdflinks[i].style.background = 'url(location.hostname://
> >> >> edonhiglkbcngojedpmbgenfgohdekoj/image.gif)';
>
> >> >> but that didn't work.
>
> >> >> On Oct 17, 9:21 pm, Pedro Junior <[email protected]> wrote:
> >> >>> location.hostname
>
> >> >>> On Oct 17, 10:59 pm, ehamiter <[email protected]> wrote:
>
> >> >>> > Title says it all, really. Using find and replace links and want to
> >> >>> > include a local image instead of calling on the http address to save
> >> >>> > bandwidth. I have the image in the directory, and manually typing in
>
> >> >>> > chrome-extension://edonhiglkbcngojedpmbgenfgohdekoj/image.gif
>
> >> >>> > works. However, when I try to use it in a script as such
>
> >> >>> > links[i].style.background = 'url(chrome-extension://
> >> >>> > edonhiglkbcngojedpmbgenfgohdekoj/image.gif) no-repeat';
>
> >> >>> > then it doesn't get called. Can I get around this?
>
> >> >>> > Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Chromium-extensions" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/chromium-extensions?hl=en
-~----------~----~----~----~------~----~------~--~---