gpt4 book ai didi

javascript - 在触发下一个功能之前等待 iframe 加载?

转载 作者:数据小太阳 更新时间:2023-10-29 04:17:17 25 4
gpt4 key购买 nike

首先:我知道应该尽可能异步运行。

我有一个函数,叫做 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-function 的外部或使用我传递给 wrap 函数的参数来执行此操作。我用一系列执行动画、播放声音等的功能来做到这一点(需要时间并且也应该按顺序执行的东西)。这就是我理想中希望它看起来像的样子。

wrap();
highlight('#one');
highlight('#two');

最佳答案

jQuery 可以在 iframe 上使用 ready 函数,就像在文档中一样。把它放在你的高亮函数中,它会在 iframe 加载完成后运行。

$("iframe").ready(function (){
// do something once the iframe is loaded
});

关于javascript - 在触发下一个功能之前等待 iframe 加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15099537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com