:已经对此“对话框”采取了操作。事件

发布于 2025-01-09 21:21:01 字数 932 浏览 1 评论 0原文

我需要在 webview 中显示网页并进行某些导航。由于 webview 不允许确认对话框通过,我想监听 webview 中的对话框事件,然后传递我自己的自定义对话框,并让用户操作成为将要执行的操作。

监听事件的 webview 非常简单:

webview.addEventListener('dialog', this.onDialogOpen);

然后我用上述方法打开对话框:

private onDialogOpen (e: any): void {
    this.dialogOn = true;
    this.dialogEvent = e;
}

现在我想要的是用户与我的对话框交互并将其操作传递给此dialogEvent,如下所示:

<button onclick="onDialogAction()">OK</button>

并运行脚本:

public onDialogAction() {
       this.dialogEvent.dialog.ok();
}

但此时我得到了标题中的错误:

webview:已对此“对话框”事件采取操作。

据我了解,由于某种原因,一旦过了一段时间,DialogEvent 就会“过时”。如果我说“this.dialogEvent.dialog.ok();”在 onDialogOpen 里面它可以工作。我还可以调用 'this.dialogEvent.dialog.ok();'如果我从 onDialogOpen 调用它,则可以从任何其他方法调用它。但是,如果我在 onDialogOpen 中说 setTimeout,它会再次停止工作。

造成这种情况的原因是什么?解决这个问题的正确方法是什么?

I need to display a webpage in webview and have certain navigations happen. Since webview does not let confirm dialogs pass through, I want to listen to the dialog events in the webview and then pass my own custom dialog and have the user action be the one that's going to be taken.

Listening to the webview for the event is easy enough:

webview.addEventListener('dialog', this.onDialogOpen);

And then I open the dialog with the said method:

private onDialogOpen (e: any): void {
    this.dialogOn = true;
    this.dialogEvent = e;
}

Now what I want is the user to interact with my dialog and pass its action to this dialogEvent, as this:

<button onclick="onDialogAction()">OK</button>

And run the script:

public onDialogAction() {
       this.dialogEvent.dialog.ok();
}

But at this point I get the error in the title:

webview: An action has already been taken for this "dialog" event.

As I understand, for some reason, the DialogEvent gets 'outdated' once some time has passed. If I say 'this.dialogEvent.dialog.ok();' inside onDialogOpen it works. I can also call 'this.dialogEvent.dialog.ok();' from any other method if I call it from onDialogOpen. However if I say, setTimeout within that onDialogOpen, it stops working again.

What would be the cause of this and what would be the right way to get around this?

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

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

发布评论

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

评论(1

轻许诺言 2025-01-16 21:21:01

对于通过搜索遇到此问题的任何人来说,解决方案都很简单:

只需添加

this.dialogEvent.preventDefault();

到 onDialogOpen() 即可。问题是任何对话框事件的默认操作都是取消,并且在加载 DOM 时由于某种原因会触发该操作。但是显然可以使用 PreventDefault() 来防止任何对话框事件进入默认状态。

The solution was simple for anyone coming to this question from a search:

Simply adding

this.dialogEvent.preventDefault();

to onDialogOpen() does the trick. The problem was the default action for any dialog event is to go with cancel, and that gets triggered for some reason when DOM is loaded. But any dialog event can be prevented from going to default with preventDefault() apparently.

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