javascript 异物在 IE10 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19739672/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
foreignobject is not working in IE10
提问by ammu
I want to draw HTML text in canvas using foreignobject element, In MDN i can see the below link (see reference), this is working fine in Chrome and Mozilla browser but not in IE10, I am using IE10.
我想使用foreignobject 元素在canvas 中绘制HTML 文本,在MDN 中我可以看到下面的链接(参见参考),这在Chrome 和Mozilla 浏览器中工作正常,但在IE10 中无法正常工作,我使用的是IE10。
Browser Mode: IE10 & Document Mode: Standards
浏览器模式:IE10 & 文档模式:标准
Reference: https://developer.mozilla.org/en/docs/HTML/Canvas/Drawing_DOM_objects_into_a_canvas
参考:https: //developer.mozilla.org/en/docs/HTML/Canvas/Drawing_DOM_objects_into_a_canvas
Error:
错误:
DOM7000: Access Denied. Resource access is restricted for cross-origin URL: 'blob:7C72C95F-3E3F-4CD6-804C-C2D8CCC06283'.
file:
文件:
Below is the code snippet : -
以下是代码片段:-
<!DOCTYPE html>
<html>
<body>
<p><canvas id="canvas" style="border:2px solid black;" width="200" height="200"></canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var data = "<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'>" +
"<foreignObject width='100%' height='100%'>" +
"<div xmlns='http://www.w3.org/1999/xhtml' style='font-size:40px'>" +
"<em>I</em> like <span style='color:white; text-shadow:0 0 2px blue;'>cheese</span>" +
"</div>" +
"</foreignObject>" +
"</svg>";
var DOMURL = self.URL || self.webkitURL || self;
var img = new Image();
var svg = new Blob([data], {type: "image/svg+xml;charset=utf-8"});
var url = DOMURL.createObjectURL(svg);
img.onload = function() {
ctx.drawImage(img, 0, 0);
DOMURL.revokeObjectURL(url);
};
img.src = url;
</script>
</body>
</html>
回答by Robert Longson
回答by GDmac
Html2canvas (beta) seems to work in Explorer 10 (at least in my virtualbox) http://html2canvas.hertzen.com/
Html2canvas(测试版)似乎适用于 Explorer 10(至少在我的虚拟机中) http://html2canvas.hertzen.com/
回答by Devil's Advocate
You could try Chromeframe, but it looks like they're retiring it next year :(
你可以试试 Chromeframe,但看起来他们明年就要退休了 :(