Solved

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

Posted on 2009-04-15
14
267 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
Comment Utility
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
Comment Utility
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
Comment Utility
Looks ok to me. What is the issue?
0
 

Author Comment

by:naeembhatti
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:naeembhatti
Comment Utility
actually i just want to refresh the already opened window.
0
 

Author Comment

by:naeembhatti
Comment Utility
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
Comment Utility
I am sorry. I do not understand what you want at all...
0
 

Author Comment

by:naeembhatti
Comment Utility
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 250 total points
Comment Utility
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 250 total points
Comment Utility
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
Comment Utility
thanks mplungjan u helps a lot.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now