Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-04-15
14
Medium Priority
?
289 Views
Last Modified: 2012-06-21
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.
0
Comment
Question by:naeembhatti
  • 7
  • 7
14 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24148690
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
 

Author Comment

by:naeembhatti
ID: 24154465
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24154961
Looks ok to me. What is the issue?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:naeembhatti
ID: 24156151
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24156846
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
 

Author Comment

by:naeembhatti
ID: 24165460
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24165590
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
 

Author Comment

by:naeembhatti
ID: 24170404
actually i just want to refresh the already opened window.
0
 

Author Comment

by:naeembhatti
ID: 24170420
oh sorry i am mean to say that i don't want to refresh a window if it is already opened
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24174120
I am sorry. I do not understand what you want at all...
0
 

Author Comment

by:naeembhatti
ID: 24181882
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
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 1000 total points
ID: 24182103
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
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 1000 total points
ID: 24182109
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
 

Author Comment

by:naeembhatti
ID: 24183803
thanks mplungjan u helps a lot.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question