Get img src from the DOM for printing

How could I access the img src using JavaScript code? I would like to access the src of an element from the DOM, which is a QR code (img), so that I can print it. For this purpose, I could create a workflow that calls the source of the img and then downloads it in a new browser window.

Screenshot 2024-01-16 190846

perhaps something like this?

// Assuming the ID of your image element is 'myImage'
var imageElement = wwLib.getFrontDocument().getElementById('id');

// Accessing the src attribute
var imgSrc = imageElement.src;

// Now you can use imgSrc as needed, for example, to print it or to use it in another part of your script
return imgSrc;

How do you get the src in the img in the first place?

1 Like

I have now found a better way. With the NPM package ‘qr code generator’ (Tutorial: Create a QR code - #3 by raydeck ), I am not generating an image that is then inserted into a DIV via JavaScript code (document.getElementById(‘placeHolder’).innerHTML = qr.createImgTag();), but the package also allows outputting a Data URL, which I can easily output into a variable during page load and then bind to an IMG container. This works excellently.

1 Like
var typeNumber = 4;
var errorCorrectionLevel = 'L';
var qr = qrcode(typeNumber, errorCorrectionLevel);
qr.addData("QR Code Content");
qr.make();

return qr.createDataURL(5);

fyi you can use the dataurl as a source of a weweb image and it is safer than setting innerHTML directly.

1 Like