简体   繁体   English

如何检查一个弹出窗口页面是否已在asp.net中打开?

[英]How to check if a pop-up window page is already open in asp.net?

I am using a javascript to open a pop-up window in asp.net. 我正在使用JavaScript在asp.net中打开一个弹出窗口。 What I want to do is when the pop-up window is already open, it will just set the focus on it and refresh the pop-up window rather than opening a new pop-up window. 我想做的是,当弹出窗口已经打开时,它将只设置焦点并刷新弹出窗口,而不是打开一个新的弹出窗口。 Else when it is close, that's the time that the pop-up window must open. 否则,必须关闭弹出窗口。

I tried below codes but didn't work.. 我尝试了以下代码,但没有用..

var winPop = false; 
function PopupCenter(pageURL, title,w,h) 
 { 
   if(winPop && !winPop.closed)
   {  
     winPop.focus();  
   }  
   else
   {  
     var left = (screen.width/2)-(w/2);
     var top = (screen.height/2)-(h/2);
     winPop = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
     winPop.focus();     
   }  

} 

Thanks in advance. 提前致谢。

You can use window.location.indexOf and by using that you can check that window is opened or not from its url 您可以使用window.location.indexOf,并使用它可以从其网址检查窗口是否打开

and another solution as per your code is that make that variable null when your window is going to close and then check that variable is null or not when it is null open new window else set focus. 根据您的代码的另一种解决方案是,当您要关闭窗口时将该变量设置为null,然后在该变量为null时检查该变量是否为null。打开新窗口,否则设置焦点。

Good Luck! 祝好运!

-> code in Parent window put this whole code in parent window like ->父窗口中的代码将整个代码放在父窗口中,例如

var w= null; var w = null;

then set variable like w= window.open(); 然后设置变量,如w = window.open();

then check that if (w!= null) then open new window else do nothing 然后检查是否(w!= null)然后打开新窗口,否则什么也不做

-> Code in Popup window and also be careful to set w= null in popup window ->弹出窗口中的代码,还要小心在弹出窗口中设置w = null

$( window ).unload(function() { w=null; });

when child window is going to close. 子窗口即将关闭时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM