gpt4 book ai didi

javascript - 在 Ember 中捕获 iframe 加载事件

转载 作者:行者123 更新时间:2023-11-29 23:41:36 24 4
gpt4 key购买 nike

我需要知道 iframe 何时加载了它的内容,我正努力坚持 Ember 的做事方式。

<iframe src="" {{action "onLoad" on="load"}}></iframe>

这看起来非常简单明了,但永远不会调用该操作。有谁知道我可能做错了什么?或者也许有更好的方法来检测这种事情?

最佳答案

更新

在my-component.hbs中创建名为my-component的组件

<iframe src="" onload={{action "onLoading"}}></iframe>

在 my-component.js 中

import Ember from 'ember';
export default Ember.Component.extend({
actions: {
onLoading() {
console.log('OnLoad');
}
}
});

即使它不在组件中也能正常工作。


在这里您可以找到支持的事件列表。 https://guides.emberjs.com/v2.10.0/components/handling-events/#toc_event-names

但是没有提到load。所以我怀疑您需要在自定义事件中提及这一点。您可以尝试在 app.js 文件中的 customEvents 对象中定义 onload 事件

App = Ember.Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
Resolver,
customEvents:{
load:'load'
}
});

引用:
https://emberjs.com/api/ember/2.14.0/classes/Ember.Application/properties/customEvents?anchor=customEvents

关于javascript - 在 Ember 中捕获 iframe 加载事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45108811/

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