将表格提交到新窗口>显示 pdf >父窗口丢失子窗口引用

发布于 2024-11-16 08:05:54 字数 679 浏览 9 评论 0原文

我有以下代码 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

骑趴 2024-11-23 08:05:54

如果我理解您想要正确执行的操作,您只需在尝试打开新窗口之前检查弹出窗口是否打开即可。
所以像这样的事情:

if (winPop ) {
winPop.focus();
    }else{
 winPop = window.open("", 'formresult', 'allthesettingshereblablah');
}

如果已经打开了一个弹出窗口,那么这应该集中在弹出窗口上。否则将打开新的。

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:

if (winPop ) {
winPop.focus();
    }else{
 winPop = window.open("", 'formresult', 'allthesettingshereblablah');
}

This should focus on poup window if there's one open already. Otherwise new one is opened.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文