views:

36

answers:

1

Hello folks, I'm developing a google chrome extension and I'm running into a relative path problem. If I give a relative path to an image and open the plugin in a certain page it will look for that image in the website's path rather than the extension's.

Any ideas?

thanks,

fbr

A: 

If your using CSS in your extension pages (background, popup, infobar, etc) then you can use relative paths:

background-image:url("/sprites.png");

The above should work, everyone uses it. But, if your using it for content scripts and you can do the same for any css, you would need to use the predefined message like:

background-image:url('chrome-extension://__MSG_@@extension_id__/sprites.png');

If you want to programmatically set it, you can use the chrome.extension.getURL syntax as following:

var url = chrome.extension.getURL('sprites.png');

These are the ways that you can refer to a specific url/image.

Mohamed Mansour
let me see if I understand, I can only use relative paths in my backround, popup, infobar, and other pages like that. If I refer to an image in a content script or css I must use a predefined message as you explained above. Is that correct?
ForeignerBR
Yep, sounds good.
Mohamed Mansour