将表格提交到新窗口>显示 pdf >父窗口丢失子窗口引用
我有以下代码 onClick 按钮
$('#someForm').attr("target", "formresult");
.......
winPop = window.open("", 'formresult', 'allthesettingshereblablah');
.......
$('#someForm').submit();
一切正常,并且新的 pdf 显示在弹出窗口中。
我想放入一个逻辑,例如如果已经有一个弹出窗口打开,则忽略按钮单击...如果我不提交,我可以进行 winPop.close 检查,它将具有正确的引用。
但是,如果我有提交(),引用就会丢失...winPop.close 不再起作用。
我知道引用已更改,因为如果我输入
winPop.onbeforeunload = function() {
alert('i am closing');
};
“我正在关闭”警报,则会在 pdf 显示之前显示,这意味着原始 winPop 已卸载,我不再拥有该引用。
我应该这样做的正确流程/方式是什么?
基本上我需要从父窗口点击“生成”按钮>>提交表单并在子窗口中打开 pdf >>如果我再次从父窗口单击“生成”按钮,则在子窗口打开时它应该忽略该单击。
I have the following code onClick of a button
$('#someForm').attr("target", "formresult");
.......
winPop = window.open("", 'formresult', 'allthesettingshereblablah');
.......
$('#someForm').submit();
everything works and a new pdf is displayed in the popup window.
I want to put in a logic like if there is already a popup open, ignore the button click... If I don't do submit, I can do winPop.closed check and it will have the correct reference.
BUT, if I have the submit(), the reference is lost...winPop.closed no longer works.
I know the reference is changed because if I put in
winPop.onbeforeunload = function() {
alert('i am closing');
};
the I am closing alert is displayed right before the pdf displays, which means that the original winPop is unloaded and I no longer have that reference.
What is the proper flow/way I should do this?
Basically I need click generate button from parent window >> submit form and opens pdf in child window >> If I click generate button from parent window again, it should ignore the click when child window is open.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解您想要正确执行的操作,您只需在尝试打开新窗口之前检查弹出窗口是否打开即可。
所以像这样的事情:
如果已经打开了一个弹出窗口,那么这应该集中在弹出窗口上。否则将打开新的。
If I understand what you're trying to do correctly, you simply can check whether popup window is open before trying to open a new one.
So something like this:
This should focus on poup window if there's one open already. Otherwise new one is opened.