开发者

Chrome extension dev: use relative links in javascript files

I've got something like...

img = document.createElement("IMG");
img.src = "image.png";

However, image.png throws back a 404 error that the file cannot be found. When it is infact there in the relativepath.开发者_JAVA技巧 This same code works when linking to an image at a web address. Is there a work around for this? how can I use relative URL's in my Chrome extension?


In chrome extensions you must use getURL()

img = document.createElement("IMG");
img.src = chrome.extension.getURL('image.png');


Try this:

img = document.createElement("IMG");
img.src = window.location.origin + "/image.png";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜