gpt4 book ai didi

c# - 从 iframe 关闭模式弹出窗口

转载 作者:行者123 更新时间:2023-12-02 18:02:59 33 4
gpt4 key购买 nike

我正在使用 modal.js 在页面中弹出对话框。当用户单击链接时,iframe 将显示在模式对话框上。该 iframe 内有一个按钮。单击按钮时,模式应关闭,页面应重定向到另一个网址。有可能吗?

最佳答案

您可以使用 jQuery bindingtrigger自定义事件。

点击时,在显示 iframe 之前,在 JavaScript 中执行以下操作:

// Bind a trigger
$('body').unbind('myUniqueEventName', SomeJavascriptFunction);
$('body').bind('myUniqueEventName', SomeJavascriptFunction);

在 JavaScript 的其他地方定义函数 SomeJavascriptFunction:

function SomeJavascriptFunction(event, extraData) {
// This is run when the button on the popup is clicked
// You can pass along data using the extraData parameter
// You can also redirect to another page
var someData = extraData.someData; // Will contain 'someValue'
}

现在我们要做的就是从 iframe 触发自定义事件。我们通过在单击按钮时在 iframe 中添加以下代码来实现此目的。

parent.$('body').trigger(
'myUniqueEventName', {
someData: 'someValue'
});
});

关于c# - 从 iframe 关闭模式弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20352471/

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