Fred J.
Fred J.

Reputation: 6049

image is not being displayed in the html page

This JS code failed to show the image, instead it gives the string [object HTMLImageElement].
How can it be fixed so that it shows the image in this location? Thanks

let signature = $('canvas.signature').get(0).toDataURL(); //earlier in the code

let w = window.open();
let doc = w.document;
doc.write(html);
doc.close();
let sigImg = new Image();
sigImg.src = signature;
let nodes = doc.querySelectorAll('td.Label');
for (var i = 0; i < nodes.length; i++) {
  var item = nodes[i];
  if (item.textContent === "User's signature:") {
    item.nextElementSibling.innerHTML = sigImg; //<--- failed to show the image
  }
}

edit
The reason I did not use item.nextElementSibling.appendChild(sigImg); is because I wanted to replace the content of the td element with the image. but even with this solution, I get a small icon, which when right click and open in new page, I get (This site can’t be reached).

Upvotes: 0

Views: 43

Answers (1)

Jaromanda X
Jaromanda X

Reputation: 1

The problem is with this

item.nextElementSibling.innerHTML = sigImg;

... change to

item.nextElementSibling.innerHTML = ''; // clear contents
item.nextElementSibling.appendChild(sigImg);

sigImg is an object, you'll find you get [object Object] displayed instead with your code, I assume

Upvotes: 2

Related Questions