Google Chrome扩展程序 - 无法使用CSS加载本地图片 [英] Google Chrome Extensions - Can't load local images with CSS

查看:1507
本文介绍了Google Chrome扩展程序 - 无法使用CSS加载本地图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Google Chrome扩展程序,它使用内容脚本功能修改网站。更具体地说,是所述网站的背景图片。

I have a simple Google Chrome extension that uses the content script feature to modify a website. More specifically, the background image of said website.

由于某种原因,我似乎无法使用本地图片,即使它们包含在扩展中。

For some reason I can't seem to be able to use local images, even though they are packed in the extension.

body {
background:#000 url('image.jpg')!important;
background-repeat:repeat!important;
}

body{ background:#000 url('image.jpg') !important; background-repeat: repeat !important; }

这是最简单的css代码,但它不工作。

That's it, the simplest css code... but it won't work. The browser doesn't load the image.

推荐答案

您的图片网址应该像 chrome-extension: //< EXTENSION_ID> /image.jpg

您最好通过javascript替换css。从文档

You would be better off replacing css through javascript. From docs:

//Code for displaying <extensionDir>/images/myimage.png:
var imgURL = chrome.extension.getURL("images/myimage.png");
document.getElementById("someImage").src = imgURL;

这篇关于Google Chrome扩展程序 - 无法使用CSS加载本地图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆