0
我有一個iframe中有DIV元素「pageContainer1」。我希望能夠在該DIV元素中添加一個畫布元素並訪問它以在其上繪製某些內容。我迄今爲止嘗試過,但似乎沒有工作。如何在iframe中創建畫布元素?
var can=document.getElementById('frame').contentWindow.document.getElementById("pageContainer1");
var canvas=document.createElement("canvas");
canvas.id="testcanvas";
can.appendChild(canvas);
var can1=document.getElementById("frame").contentWindow.document.getElementById("testcanvas");
var ctx= can1.getContext('2d');
ctx.beginPath();
ctx.moveTo(20,20);
ctx.lineTo(100,100);
ctx.stroke();
請建議一些方法來做到這一點,即使通過使用jQuery。
你是什麼意思,我已經有權訪問「畫布」。我想你不明白我的問題。我想添加一個畫布在iframe中的DIV元素中。怎麼做?有什麼建議麼。上面的代碼顯示錯誤。「undefined不是函數」for line can.appendChild(canvas) – user3454558