[英]Unable to target child element of Canvas
Here is my code 这是我的代码
javascript: (function() {
var canvas = document.getElementById("app-view").children[1];
var img = canvas.toDataURL("image/png");
window.open(img);
})();
and here is the app element where I wish to target the second canvas element "children 1 " but it's not working for some reason and always gets stuck at the first element. 这是app元素 ,我希望将第二个canvas元素“ children 1 ”作为目标,但由于某种原因它无法正常工作,并且总是卡在第一个元素上。 A solution will be much appreciated, thanks in advance!
一个解决方案将不胜感激,在此先感谢!
In the picture it always targets the first canvas in yellow but I need the one displayed in blue. 在图片中,它始终以黄色为第一个画布,但我需要以蓝色显示。 You can test the code by saving the script as a bookmark in your browser.
您可以通过将脚本另存为浏览器中的书签来测试代码。
Haven't worked out why toDataURL gets the data of the left canvas, but if you wanted to save the canvas, you can isolate it with 还没有弄清楚为什么toDataURL获取左画布的数据,但是如果要保存画布,可以使用以下方法隔离它
var can = document.getElementById("app-view").children[1];
jQuery("body > *").remove();
jQuery("body").append(can) ;
and then now you can right click and save the canvas 然后现在您可以右键单击并保存画布
这对我有用:
document.getElementById('app-view').childNodes[1]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.