gpt4 book ai didi

javascript - 无法在 Chrome 中刷新父窗口

转载 作者:行者123 更新时间:2023-11-30 16:41:39 24 4
gpt4 key购买 nike

我使用 showModalDialog 从 Javascript 打开一个弹出窗口。我有这个应用程序是 ASP.Net,我确实在弹出窗口中回复。

 window.showModalDialog('childpage.aspx', '', 'titlebar:no;status:no; help:no; center:yes; edge:raised;dialogWidth:950px;dialogHeight:950px;');

在弹出页面中,我添加了 onunload 事件以在我们关闭弹出窗口时刷新父页面。

<body onunload="window.opener.reload();">

我使用以下代码在 Asp.net 中单击按钮关闭窗口:

this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "var ua = window.navigator.userAgent; var msie = ua.indexOf(\"MSIE \"); if (msie > 0) { window.close();  } else { parent.document.getElementsByTagName('dialog')[0].close();  }", true);

它在 IE 中运行良好。在 Chrome 中,我可以关闭窗口,但无法刷新页面。即使在 Chrome 中关闭弹出窗口也不是直截了当的。 window.close 不起作用,所以我在上面的脚本中使用了一个条件来关闭基于浏览器的弹出窗口。当浏览器是 chrome 时,谁能建议如何刷新父页面?我已经尝试了本论坛和其他论坛中所有以前的建议,但没有成功!!

我也试过这个...

this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "var ua = window.navigator.userAgent; var msie = ua.indexOf(\"MSIE \"); var isFirefox = typeof InstallTrigger !== 'undefined'; if (msie > 0 || isFirefox) { window.close();  } else { parent.document.getElementsByTagName('dialog')[0].close();  } window.opener.location.reload(true);", true);

最佳答案

@user2169261

我在使用 chrome 时遇到了类似的问题。 firefox 和 IE 中的父窗口可以正确刷新,但 chrome 中不能。下面是我用来让它工作的代码:


父窗口代码(文件名:test.php)

<html>
<head>
<title>Parent window</title>
</head>
<body>
<h2>This is the Parent window.</h2>
<a href="javascript:void(0);" NAME="" title=""
onClick=window.open("test2.php","Ratting","width=550,height=170,0,status=0,top=200,");>
Click here to open the child window</a>
</body>
</html>



子窗口代码(文件名:test2.php)

<html>
<head>
<title>Child Window</title>
<script type="text/javascript">
function refreshAndClose()
{
window.close();
if (window.opener && !window.opener.closed)
{
window.opener.location.reload();
}
}
</script>
</head>
<body>
<h2>Click the button below to close this window and refresh the parent window</h2>
<input type="button" value="submit" onclick="return refreshAndClose()"/>
</body>
</html>

这可能不是您要找的,但希望对您有所帮助。

关于javascript - 无法在 Chrome 中刷新父窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31881864/

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