IE11等待承诺结果

发布于 2025-01-27 00:18:45 字数 261 浏览 2 评论 0 原文

我该如何等待Promise/Script.onload执行即可执行:.then(),.catch(),等待/异步和回调IE11。与CPP上的睡眠(100)相当的东西。如果我做一个循环'while(loadflag == false);'并检查标志是否已更改,浏览器悬挂并停止响应。我想取得类似的成就:

ScriptLoad(script);
functionFromLoadedScript(); 

但是我无法做到这一点...请帮助解决这个问题

How can I wait for promise/script.onload to execute without: .then(), .catch(), await/async and callback IE11. Something comparable to the Sleep(100) on cpp. If I do a loop 'while(loadFlag == false);' and check if the flag has changed, the browser hangs and stops responding. I want to achieve something like:

ScriptLoad(script);
functionFromLoadedScript(); 

but i cant make this... Pls help with this problem

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情痴 2025-02-03 00:18:45

如果您有状态标志,则可以使用 setInterval 对状态进行轮询。

ScriptLoad(script);
var intervalID = setInterval(function () {
    if (loadFlag === true) {
        clearInterval(intervalID);
        functionFromLoadedScript(); 
    }
}, 100);

您还可以在IE中加载 Promise Polyfill库,因此您可以使用然后使用/ catch async /不需要等待。承诺可以通过链接做同样的事情。如果您真的想使用 async /等待可以使用 typescript 到目标 es5 typescript 可以转移 async /等待使用 Promise> Promise> Promise 将在IE中运行。为此,您必须定位ES5,并且必须在IE中加载 Promise polyfill库。

If you have a status flag you could use setInterval to poll the status.

https://developer.mozilla.org/en-US/docs/Web/API/setInterval

ScriptLoad(script);
var intervalID = setInterval(function () {
    if (loadFlag === true) {
        clearInterval(intervalID);
        functionFromLoadedScript(); 
    }
}, 100);

You could also load a Promise polyfill library in IE so you can use then/catch. async/await are not required. Promises can do the same with chaining. If you really want to use async/await you can use TypeScript to target ES5. TypeScript can transpile async/await to the equivalent code using Promise that will run in IE. For this to work you must target ES5 and you must load a Promise polyfill library in IE.

与君绝 2025-02-03 00:18:45

不幸的是,这是不可能的。

Unfortunately, this is not possible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文