Use results.css({"width": width, "height": height}); or results.css("width", width); results.css("height", height); instead, as shown in the following example:
Standard Script
Name: Dynamic Image
Selector: #dynamic-image
var field = "",
result = "file:///C:/PPWorkDir/resources/images/";
field = record.fields.fieldName;
if (field !== "") result += field;
var info = resource(result);
if (info) {
var width = info.width + "pt",
height = info.height + "pt";
results.attr("src", result);
//results.css({"width": width, "height": height});
results.css("width", width);
results.css("height", height);
}
At the moment I had to work on things other than Connect Designer and I did not have the time to test this yet⊠Iâll come back here and report my findings when I have the time to get back to it.
p.s.: I will now see if the background image solution will work for me, but I doubt that, since I have images in different resolutions that need to be displayed correctly and that will probably not work with a div/box.
Thank you for sharing the applied JavaScript code.
In response to your latest reply I would like to share the following questions with you:
Can you please confirm whether one of the three conditions are met?
Can you also let me know please which selector youâre using for the applied JavaScript code? Is the Standard Script to which youâve applied the JavaScript code targeting an <img>-element, for example?
P.S. Please keep in mind that dimensions.width returns a value in points (pt).
Thanks, that was what it looked in the first try some time ago, the code posted above was the end of a long time of experimentation to get this to work. My latest version did not throw any syntax errors, anyway âŠ
if (record.fields.ExternesSystemBezeichnung == "Paradis pour gourmets") {
showLogoImage("images/img/logos/PA/PD_FR_Paradis_pour_gourmets_500.png",4,4)
}
if (record.fields.ExternesSystemBezeichnung == "Paradijs voor fijnproevers") {
showLogoImage("images/img/logos/PA/PD_NL_Paradijs_voor_fijnproevers_500.png",4,4)
}
if (record.fields.ExternesSystemBezeichnung == "Welt der VerfĂŒhrung") {
showLogoImage("images/img/logos/PA/PD_DE_Welt_der_Verfuehrung_500.png",4,4)
}
else {
results.show();
}
/* showLogoImage
Parameter:
imgsrc = Pfad zum Bild in den Bildresourcen
teilerX = Divisor zum Verkleinern der Bildbreite auf gewĂŒnschtes Format
teilerX = Divisor zum Verkleinern der Bildhöhe auf gewĂŒnschtes Format
*/
function showLogoImage(imgsrc, teilerX, teilerY) {
results.attr("src", imgsrc);
dimensions = resource(imgsrc);
width = (dimensions.width / teilerX) + "pt";
height = (dimensions.height / teilerY) + "pt";
results.css("width", width);
results.css("height", height);
results.show();
}
Since I need the function to show/change the images in other conditional scripts I would like to make it global.
I created a Javascript file called âfunctionsâ in the Resource tree under âJavaScriptsâ, did cut the function from the consition code and pasted it into the functions file in the resource tree. But in the condition Javascript the function now is shown as âunknownâ.
Is the resource tree not the right place to do this? If not, how can I make functions like this global?