我有一个 html 页面(静态 html)。在其中我有 anchor 标记 (.windowOpener
) 和一个显示状态的隐藏 div(.status
)。当用户单击 anchor 标记时,会打开一个窗口:
<a href="#" class='windowOpener' onClick="window.open('newPage.html','New Page','resizable,height=580px,width=357px'); return false;">Click here</a>
<div class='status' style='display:none'>Successful</div>
单击此链接后,将打开一个单独的窗口。在这个新窗口中,有一个链接为
<a class='paymentButton' href='javascript:void(0)'>Do the payment</a>
现在,单击此 anchor 标记 (. paymentButton) 时,我想关闭新窗口并希望使“status”div 在第一个窗口中可见。我不想使用模态。
可以这样做吗?任何帮助将不胜感激...
提前谢谢您。
最佳答案
使用window.parent
访问父窗口:
$(document).on('click', '.paymentButton', function() {
parent.showStatusDiv();
});
并在父窗口中声明showStatusDiv()
函数:
function showStatusDiv() {
$('.status').show();
}
注意
如果有不止一层窗口,请使用window.top
访问最顶层的窗口
关于javascript - 单击另一个窗口中的按钮后,使一个窗口中的 div 可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52814003/