Avatar of tuchfeld
tuchfeld
 asked on

Workaround for <foreignObject> that is not supported in IE

Hello,
Can you please direct me how to do so?
The folowing code works just fine in Chrome.
Thanks, Aryeh.
function html_to_img(html) {
  var data = '<svg xmlns="http://www.w3.org/2000/svg" width="' + 400 + '" height="' + 200 + '">' +
          '<foreignObject width="100%" height="100%">' +
          '<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:18px; font-family: david; word-wrap: break-word;">' +
          html +
          '</div>' +
          '</foreignObject>' +
          '</svg>';

  var DOMURL = window.URL || window.webkitURL || window;
  var svg = new Blob([data], { type: 'image/svg+xml;charset=utf-8' });
  var url = DOMURL.createObjectURL(svg);
  img.src = url; // some Image Element.
}

Open in new window

JavaScript

Avatar of undefined
Last Comment
Alexandre Simões

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Alexandre Simões

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy