我正在尝试使用Javascript将canvas放入iframe元素,但是当我执行代码时,我得到了:debuger中的undefined 这个代码可以有人帮助我吗?
function submitTryit() {
var ifr = document.createElement("iframe");
ifr.setAttribute("id", "iframeResult");
document.getElementById("iframewrapper").innerHTML = "";
document.getElementById("iframewrapper").appendChild(ifr);
canvas();
}
function canvas(){
var ifrr = document.getElementById("iframeResult");
var iframediv = (ifrr.contentWindow.document || ifrr.contentDocument.document);
var canv = document.createElement('canvas');
canv.setAttribute("id", "mycanvas");
iframediv.body.appendChild(canv);
}
答案 0 :(得分:0)
你的所有代码都很好,问题是你太快运行了;您尝试在页面上存在之前获取touch
。解决方案很简单,在确定页面已加载
iframewrapper
submitTryIt()
window.onload = function()
{
submitTryit();
}
window.onload = function() {
submitTryit();
}
function submitTryit() {
var ifr = document.createElement("iframe");
ifr.setAttribute("id", "iframeResult");
document.getElementById("iframewrapper").innerHTML = "";
document.getElementById("iframewrapper").appendChild(ifr);
canvas();
}
function canvas() {
var ifrr = document.getElementById("iframeResult");
var iframediv = (ifrr.contentWindow.document || ifrr.contentDocument.document);
var canv = document.createElement('canvas');
canv.setAttribute("id", "mycanvas");
iframediv.body.appendChild(canv);
}