Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I am using following code to open a aspx page as popup.
btnSearch.Attributes.Add("onclick", "Javascript:var PopUpWin = window.open('SearchPR.aspx','_blank','width=600,height=380,title=yes,toolbar=no,location=no,resizable=no,status=no');return false;")
My issue is if the popup window is already open, i dont want to open it again. Right now, if popup is already open, and i click the btn again, it open another popup window.
 
How do I fix this?
Posted 8-Mar-11 10:38am
Edited 8-Mar-11 10:55am
v2
Comments
SAKryukov at 8-Mar-11 16:53pm
   
I would suggest you remove all tags except Javascript, they are irrelevant. This is a valid Question and a very typical issue, so I vote 5. --SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

replace "window.open" by "window.showModalDialog"
 
For detail please navigate
 
If you have more concerns, please let me know.
  Permalink  
v2
Comments
Rubaba at 9-Mar-11 15:06pm
   
exactly 5.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Give same name to the new windows and it will open in the same window all the time.
 
Right now, you must be using different name in all the cases for the new window. This forces to open in the different one and not in the existing one only.
 
For ex: 'myWindowName' is the name that needs to be same all the time.
var reportWindow = window.open('CostByProject.aspx', 'myWindowName','height=650,width=900,resizable=1,status=yes,scrollbars=1,toolbar=no,menubar=no,location=no');
 
Read the details here: MSDN: Window.Open()[^]
 
P.S.: "_blank" will always trigger a new window. Replace it with a fixed name and you will be set.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

The below script might be useful -
 
<script language="JavaScript"><!--
var windowHandle = null;
var windowHandle_closed = false;
 
function openWindow() {
    windowHandle = window.open('SearchPR.aspx','_blank','width=600,height=380,title=yes,toolbar=no,location=no,resizable=no,status=no');
    if (windowHandle_closed) {
        windowHandle_closed = false;
    }
}
 
function closeWindow() {
    if (windowHandle != null) {
        if (!windowHandle_closed) {
            windowHandle_closed = true;
            windowHandle.close();
        }
    }
}
//--></script>
 


HTH
Rajeev


Please vote and mark the answer as accepted if this helps

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 sanket saxena 355
1 Abhinav S 303
2 Sergey Alexandrovich Kryukov 299
3 OriginalGriff 225
4 thatraja 220
0 Sergey Alexandrovich Kryukov 8,497
1 OriginalGriff 4,850
2 Peter Leow 3,839
3 Maciej Los 3,535
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 9 Mar 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid