You need to sign in to do that
Don't have an account?
Ron McCrerey
Static Resource Zipped Image File won't Load from Javascript
I have a Zipped Static Resource which includes a .js file and several images. The images load fine from the HTML with following :
<img src = "{!URLFOR($Resource.images,'img/')}ToolBumper24S7DS120x140.png"/>
but the following code in Javascript produces an undefined error.
image.onload = image.addEventListener("load", function(){
canvas.drawImage(image, x, y, w, h);
}, false);
image.onload = image.addEventListener("error", function(e){
console.log("error loading image " + is + " " + JSON.stringify(e) );
});
image.src = "{!URLFOR($Resource.images,'img/')}ToolBumper24S7DS120x140.png";
Why does the image not load?
<img src = "{!URLFOR($Resource.images,'img/')}ToolBumper24S7DS120x140.png"/>
but the following code in Javascript produces an undefined error.
image.onload = image.addEventListener("load", function(){
canvas.drawImage(image, x, y, w, h);
}, false);
image.onload = image.addEventListener("error", function(e){
console.log("error loading image " + is + " " + JSON.stringify(e) );
});
image.src = "{!URLFOR($Resource.images,'img/')}ToolBumper24S7DS120x140.png";
Why does the image not load?
All Answers
<img src = "{!URLFOR($Resource.images,'img/ToolBumper24S7DS120x140.png')}"/>
Expected an identifier and instead saw '<'
I believe the problem is that "{!URLFOR($Resource.images,'img/')}" this is not being resolved but is being processed as as a string literal.
In other words it is being processed as "!URLFOR($Resource.images,'img/')}ToolBumper24S7DS120x140.pngToolBumper24S7DS120x140.png')}"
and it should be resolved and processed as something like this ''/resource/1438357662000/images/img/ToolBumper24S7DS120x140.png''