开发者

Chrome extension dev: use relative links in javascript files

开发者 https://www.devze.com 2023-02-05 07:28 出处:网络
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

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

精彩评论

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