2013-01-17 57 views
2

我在stackoverflow中搜索了这个问题,并看到类似的问题(但不是我正在寻找的),但该解决方案似乎不起作用。我只是jQuery中的新手,我需要你的帮助才能完成这项工作。 (交叉手指)如何在jQuery UI对话框关闭时重新加载父页面?

所以我有一个带有按钮的网页(例如parentPage.html)。当按钮被点击时(openItemPopup函数被执行),它使用jQuery UI打开一个模态对话框。模态对话框“#contentWindow”的内容是一个不同的页面(例如modalDialog.html)。


function resetContent() { 
$('#contentFrame').attr('src', '/images/ajax-loader.gif'); 
} 

function closeContent() { 
$('.ui-dialog-titlebar-close').click(); 
} 

function openItemPopup(){ 

$('#contentWindow').dialog({width:980, modal: true, 
     close: function(ev, ui) { resetContent(); } 
}); 
} 

内部modalDialog.html,当点击锚时,它执行一些逻辑和它需要动态地关闭该模态对话框。有人告诉我用这个和这个已经工作:


   // refresh parent page before closing 
       // doesn't work 
       location.reload(true); 

       // close the modal dialog 
       window.top.closeContent(); 
       return false; 
       window.location='javascript:void();'; 

我的问题是:我只需要在关闭模式对话框之前刷新parentPage.html。你在上面看到我试图使用location.reload(true);但它重新加载了模式对话框而不是parentPage.html。我无法发布图片,但它说* “无效的Web应用程序会话” *

我也尝试过window.top.location.reload();它似乎工作。它会重新加载parentPage.html并关闭模式对话框。

   // refresh parent page before closing 
       // seems working but has error 
       window.top.location.reload(); 

       // close the modal dialog 
       window.top.closeContent(); 
       return false; 
       window.location='javascript:void();'; 

然而,它说:“无效的Web应用程序会话。” - 就像使用location.reload(true);时的情况一样。我不知道为什么会发生这种情况,以及如何解决这个问题。我甚至不确定window.top.location.reload是否是正确的方法。

FYI:我试图刷新parentPage.html能够获取数据从模态对话框后面。之前,modalDialog.html用作简单的html页面。诸如列表和字段之类的数据可以从modalDialog.html正确返回到parentPage.html。他们希望将其转换为模式对话框以防止页面刷新。有人告诉我可以使用AJAX,但这是一项很多工作。另外,我不是它的主人。如果您有更好的建议,请随时告诉我!

我希望你能帮我解决这个问题。提前致谢!!!

+0

function reloadContent() { location.reload(); } 

在你modalDialog.html通过调用函数尝试'location.reload();' http://www.w3schools.com/jsref/met_loc_reload.asp – simplyray

+0

location.reload();重新加载模态对话框而不是父页面。 – afewknows

+0

你的模态对话框是一个iframe吗?否则'位置。重载();'真正应该做的伎俩 - 已经与jQuery颜色框和Ajax请求之前完成它。 编辑:增加了一个答案有不同的方法。 – simplyray

回答

2

试试这个:在您的parentPage.html添加一个新功能:

parent.reloadContent(); 
+0

我试着添加它。它刷新了父页面,但它显示“无效的Web应用程序会话” – afewknows

5

在你的对话框使用close: function (ev, ui) { window.location.reload() }

相关问题