我有一个在 iframe 中打开的 colorbox 窗口。在该窗口内,我有一个用户可以单击的链接,理想情况下,我希望关闭当前的 colorbox 窗口并打开一个新的 colorbox 窗口(再次在 iframe 中)或将新内容加载到现有 iframe 中。
我的第一个窗口打开如下:
$.colorbox({ width: "800px", height: "580px", open: true, iframe: true, href: '/App/View?id=' + id });
当我点击第一个窗口中的链接时,会触发以下内容:
$.colorbox({ width: "800px", height: "580px", iframe: true, href: "/App/Note?nodeId=" + nodeId })
我尝试关闭第一个窗口:
parent.$.colorbox.close();
但这最终会关闭两个窗口。
如果我不尝试关闭,第二个窗口将在第一个窗口的内容中打开,并且我有 2 个边框、2 个关闭按钮等。
有什么想法吗?
谢谢。
最佳答案
尝试执行此操作,这将关闭第一个颜色框,然后使用父级上下文打开新的颜色框。
parent.$.colorbox.close();
parent.$.colorbox({ width: "800px", height: "580px", iframe: true, href: "/App/Note?nodeId=" + nodeId });
实际上,您应该在父页面中有一个函数来执行此操作。
function OpenNote(noteId){
$.colorbox.close();
$.colorbox({ width: "800px", height: "580px", iframe: true, href: "/App/Note?nodeId=" + nodeId });
}
然后在单击 View 页面内的链接并传递 noteId 时调用此函数。
parent.OpenNote(id);
关于jquery - 带 iframe 的 Colorbox - 关闭然后打开另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9708719/