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 sho开发者_JS百科uld 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.
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.
精彩评论