修复以下 JavaScript 代码包含我的最新任务:
// submit the form in the iframe:
document.getElementsByTagName("iframe")[0].contentWindow.dojo.byId(buttonId).click();
// wait 50msec for result to be loaded:
window.setTimeout(function(){
// get documentId of newly created document from result
var docId = document.getElementsByTagName("iframe")[0].
contentWindow.dojo.byId("documentIdDiv").innerHtml;
// put documentId into the outer form
Ext.getCmp("form").getForm().findField("documentId").setValue(docId);
// submit outer form
Ext.getCmp("form").getForm().submit({
...
});
}, 50);
// TODO: Error if result is not available after 50ms.
我现在必须找到一种方法来在 iframe 重新加载后执行匿名函数。
我想过在 iframe 上使用 body onload,但我不能,因为我必须将它插入到新页面的正文中。
最佳答案
哈哈,尝试让它在 JSFiddle 上工作更加困难。因为他们加载 javascript 和 html 是分开的。无论如何,这应该可行。
//function that happens when loaded
function loaded() {
b.innerHTML = 'Call Back Worked';
};
//gets elements and sets them to variables
var b = document.getElementById('callback')
var a = document.getElementById("myframe");
//listens to load event
a.addEventListener("load", loaded());
关于Javascript 等待 iframe 重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27547388/