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 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  
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  

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

  Print Answers RSS
0 OriginalGriff 389
1 Sergey Alexandrovich Kryukov 362
2 CPallini 130
3 Abdul Samad KP 125
4 Richard MacCutchan 110
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,680
2 CPallini 4,850
3 George Jonsson 3,454
4 Gihan Liyanage 2,522


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100