我有一个页面,使用元刷新
每5秒刷新一次<meta http-equiv="refresh" content="5;url=terminal.asp?x=<%= runningInterval %>" />
该页面有多个动态生成的jQuery对话框。感谢这篇文章中出色的建议:Dynamic jquery dialog pop ups
我的问题是当对话框弹出时,它会在父刷新发生时自动消失。无论父/开启者做什么,我如何强制保持对话框保持?我希望用户在希望时关闭对话框。谢谢你
答案 0 :(得分:1)
基本上,对话框是父元素内的子元素,因此刷新父元素(例如清除所有子元素并重新填充)将删除对话框。如果你这样做,你无法解决这个问题。如果可能的话,我会将对话框窗口指向另一个未刷新的元素。
例如,直接在文档中。
答案 1 :(得分:1)
对话框只是页面的另一个元素,因此如果当前页面消失,它将会消失。
要实现“持久性”对话框,您必须通过删除和重新创建HTML元素,或(1)“重新绘制”整个当前页面(对话框除外);或(2)设置iframe
,在父级中打开对话框并更改iframe
中的页面。 - 由于第一点是(很难但是)直截了当,让我举一个第二种方法的例子。
CHECK the DEMO FIDDLE here. (点击here to open it in edit mode)
父页面将有一个隐藏的对话框(可能还有其他内容)和一个 iframe
,它占据了整个页面:
<div id="dialog1" style="display:none;">Parent Dialog!</div>
<iframe src="http://my.iframe.address.com" height="100%"></iframe>
用JavaScript打开对话框(检查the fiddle以获取完整示例。):
function openDialog() { // called by the inner iframe
$('#dialog1').dialog({ /*...*/ });
}
现在iframe
页面可以像任何其他页面一样(当然可以用作iframe
)。 Check the used demo page fiddle here.在重定向之前,它会调用父级打开对话框:
parent.openDialog(); // calls function on parent that will open a dialog
window.location.href = "http://www.imdb.com"; // and then redirects itself
像往常一样,使用iframe
时,请注意同源策略。