[英]How to wait for API Call Data before next function is triggered?
[英]Wait for iframe to load before next function is triggered?
首先,我知道如果可能的话,事情应该异步运行。
我有一个函数,称为wrap:
本质上,它将当前页面加载为iframe。 我需要它以便即使在页面上单击链接也能保持javascript运行。
function wrap(){
event.preventDefault();
var pathname = window.location.pathname;
$('body').html('<iframe id="wrapper" src="'+ pathname +'" >')
$('iframe').load(function (){
//this is where the magic outght to happen
});
}
当运行换行时,我想开始处理iframe的内容。 对于应用程序的结构,我需要从wrap函数的ouside或使用我传递给wrap函数的参数来完成。 我通过执行动画,播放声音等一系列功能来做到这一点(需要时间的东西也应该顺序执行)。 这就是我理想的样子。
wrap();
highlight('#one');
highlight('#two');
jQuery可以在iframe上使用ready函数,就像在文档中一样。 将其放在突出显示功能中,它将在iframe加载完成后运行。
$("iframe").ready(function (){
// do something once the iframe is loaded
});
您可以创建一个函数:
function iframeready() {
// code after iframe is loaded
}
并将此函数作为iframe加载事件的回调传递,这样您的代码将在iframe加载后执行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.