how to open multiple popup windows only in case if it not open or closed?

i am workin on a chat module,
i need to open a popup window if other user gets a new message, if popup window is not open,
e.g if user got 2 messages from user A and user B
then only 2 popups will be open and if user close 2nd popup then only 2nd will be open because it is currently not open,
i don't want window.open function if window is already opened.
it should work in firefox and ie. please.
naeembhattiAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
You mean

function popWin(url,name) {
 if (pops[name] && !pops[name].closed) return false; // do not refresh
  else pops[name]=window.open(url,name,'width=500,height=300');
  if (!pops[name]) return true;
  setTimeout('pops["'+name+'"].focus()',100);  
  return false;
}

Open in new window

0
 
Michel PlungjanIT ExpertCommented:
You mean

<script>
var pops = new Array()
function popWin(url,name) {
  if (pops[name] && !pops[name].closed) pops[name].location=url; 
  else pops[name]=window.open(url,name,'width=300,height=400');
  if (!pops[name]) return true;
  setTimeout('pops["'+name+'"].focus()',100); }
  return false
}
</script>
<a href="page1.html" target="pop1" onClick="return popWin(this.href,this.target)">Pop1</a>
<a href="page2.html" target="pop2" onClick="return popWin(this.href,this.target)">Pop2</a>

Open in new window

0
 
naeembhattiAuthor Commented:
hmm i am still facing a problem please see this code i have updated with your provided code.
var pops = new Array();
function popWin(url,name) {
  if (pops[name] && !pops[name].closed) pops[name].location=url;
  else pops[name]=window.open(url,name,'width=300,height=400');
  if (!pops[name]) return true;
      setTimeout('pops["'+name+'"].focus()',100);  
  return false;
}
function handlePrivateChat(){
    if (privateReq.readyState == 4) {
        var response = eval("(" + privateReq.responseText + ")");    
        if(CheckBrowser()==true)
            total_array_length        = response.messages.message.length;
        else    
            total_array_length        = response.messages.message.length-1;
           
        for(i=0;i < total_array_length; i++) {
                popWin('private_chat.php?id='+response.messages.message[i].id, 'Privat_Chat'+'_'+response.messages.message[i].id);
        }
    }
}

please help


0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Michel PlungjanIT ExpertCommented:
Looks ok to me. What is the issue?
0
 
naeembhattiAuthor Commented:
it just keep opening and opening  hmmmm like it is just bluring like a window is refreshing
e.g i opened a window named Privat_Chat_1
and it is already open
it again check Privat_Chat_1 so it refreshes that is the problem i need that if window is not open already don't go to open it again, do u got my problem?
0
 
Michel PlungjanIT ExpertCommented:
Works for me

Try reloading this a few times and see it only opens 3 windows

<script>
var pops = new Array();
function popWin(url,name) {
 if (pops[name] && !pops[name].closed) pops[name].location=url;
  else pops[name]=window.open(url,name,'width=300,height=400');
  if (!pops[name]) return true;
  setTimeout('pops["'+name+'"].focus()',100);  
  return false;
}
function handlePrivateChat(){
  var ids = new Array(1,2,1,3,2,3,1,2,3)
  var total_array_length= ids.length           
  for(i=0;i < total_array_length; i++) {
    popWin('http://google.com/search?q='+ids[i]+' OR '+new Date(), 'Privat_Chat_'+ids[i]);
  }
}
handlePrivateChat()
</script>

Open in new window

0
 
naeembhattiAuthor Commented:
i do have a function like it recall it again e.g then it creates problem



function handlePrivateChat(){
  var ids = new Array(1,2,1,3,2,3,1,2,3)
  var total_array_length= ids.length          
  for(i=0;i < total_array_length; i++) {
    popWin('http://google.com/search?q='+ids[i]+' OR '+new Date(), 'Privat_Chat_'+ids[i]);
  }
}
 
setTimeout('handlePrivateChat()',100);   
please help.

Open in new window

0
 
Michel PlungjanIT ExpertCommented:
can you PLEASE be more specific.

"then it creates problem" does not tell me anything

If I run the code below, then each second 3 windows are refreshed. If I close one, a new one with the same name is opened

To stop the code, close or leave the page with the script

<script>
var pops = new Array();
function popWin(url,name) {
 if (pops[name] && !pops[name].closed) pops[name].location=url;
  else pops[name]=window.open(url,name,'width=500,height=300');
  if (!pops[name]) return true;
  setTimeout('pops["'+name+'"].focus()',100);  
  return false;
}
function handlePrivateChat(){
  var ids = new Array(1,2,1,3,2,3,1,2,3)
  var total_array_length= ids.length           
  for(i=0;i < total_array_length; i++) {
    popWin('http://google.com/search?q='+ids[i]+' OR '+new Date(), 'Privat_Chat_'+ids[i]);
  }
}
setInterval('handlePrivateChat()',1000)
</script>

Open in new window

0
 
naeembhattiAuthor Commented:
actually i just want to refresh the already opened window.
0
 
naeembhattiAuthor Commented:
oh sorry i am mean to say that i don't want to refresh a window if it is already opened
0
 
Michel PlungjanIT ExpertCommented:
I am sorry. I do not understand what you want at all...
0
 
naeembhattiAuthor Commented:
actually when i execute this code it open 3 pop ups but it refreshes the pop ups that are open before, like if a pop up name A is already open i don't want to refresh it. if it is not open then just open it.

actually this function handlePrivateChat() has to execute after every second so window named A should not be refreshed????
or u can give me other solution


0
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
or even


function popWin(url,name) {
  if (pops[name] && !pops[name].closed) {pops[name].focus(); return false;} // do not refresh
  else pops[name]=window.open(url,name,'width=500,height=300');
  if (!pops[name]) return true;
  setTimeout('pops["'+name+'"].focus()',100);  
  return false;
}

Open in new window

0
 
naeembhattiAuthor Commented:
thanks mplungjan u helps a lot.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.