我有一个程序 (pgmA),它创建一个基本页面,左侧有 4 个垂直选项。当用户单击其中一个选项时,程序 (pgmB) 将在 iframe 中运行,从数据库中检索信息并显示一些信息以及 4 个水平选项卡。然后,用户可以单击选项卡,然后会显示一个包含更多信息的弹出窗口。要隐藏弹出窗口,用户可以单击“关闭”或 iframe (pgmB) 内的任意位置。以下代码用于当用户在 iframe (pgmB) 内单击时隐藏弹出窗口:
$(document).mouseup(function(e) {
var cont = $('#PopUpInformation');
if (!cont.is(e.target) &&cont.has(e.target).length === 0) {
cont.hide();
}
});
这部分效果很好,但我也希望用户能够单击页面上的任何位置(pgmA)来隐藏弹出窗口,这是我无法弄清楚的。帮助...
最佳答案
我认为 parent
可以实现这一点,我猜测您问题中的代码位于 <iframe/>
内。所以,你可以尝试这样的事情。
$(document).add(parent.document).mouseup(function(e) {
var cont = $('#PopUpInformation');
if (!cont.is(e.target) && cont.has(e.target).length === 0) {
cont.hide();
}
});
关于javascript - 检测 iframe 外部的点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19321835/