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";
精彩评论