Link to home
Create AccountLog in
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

ASKER CERTIFIED SOLUTION
Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account