我使用javascript window.opener属性刷新子窗口中的父窗口。
父窗口只包含一个带有数据的表和子窗口的链接,当打开子窗口时,使用window.opener属性在父窗口中执行js函数,父窗口中的js函数使用ajax刷新表。
问题在于window.opener,因为当用户使用右键单击(contextmenu)打开链接时是空的。
示例:
parent.jsp
<html>
<head>
<script type="text/javascript">
function refreshTable() {
// ajax code to refresh the #theTable table, not important for this question
}
</script>
</head>
<body>
<a href="/folder/child.jsp" target="_blank">OpenChild</a>
<table id="theTable">
<tr>
<td>...</td>
</tr>
</table>
</body>
</html>child.jsp
<html>
<head>
<script type="text/javascript">
$(document).ready( function() {
// opener is NULL when child is opened with right click
window.opener.refreshTable();
});
</script>
</head>
<body>
...
</body>
</html>发布于 2021-02-02 11:17:37
好的,我知道很晚了,但我把这个留在这里以备将来之用。
添加
rel="opener" 到target="_blank“链接
<a href="/folder/child.jsp" target="_blank" rel="opener">OpenChild</a> 打开器将通过子页面传递。
基于https://developer.mozilla.org/en-US/docs/Web/API/Window/opener
在以下情况下,浏览器不填充window.opener,但将其保留为空:
sidenote:顺便说一句,如果您打开一个页面时,右击或左键是没有区别的。
发布于 2016-08-05 15:14:46
根据您的需求,您可以始终在您的window.opener页面中设置child.jsp:
window.opener="https://www.google.com/";https://stackoverflow.com/questions/38792184
复制相似问题