Solved

Check if named window exisits

Posted on 2003-12-02
10
1,818 Views
Last Modified: 2011-09-20
Is it possible to check if a window by a certain name is already open?

example:

I have windows named x, y and z

say the window that opened these windows wanted to open a window named y it would check to see if it's already open. If it is then it wouldnt try to open it again
0
Comment
Question by:chrisnetonline
10 Comments
 
LVL 10

Expert Comment

by:NetGroove
ID: 9862932
Yes, that is posible.

Open again a blank window with taht name and look for some attributes.
If that attributes are not there, then open the correct window.

Like this:
  wx = window.open('','winXname');
  if(wx.titel!=wx.title){
     wx.close();
     wx = window.open('wx.htm', 'winXname', 'height=100,width=100');
  }

  // use wx now.

0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9862939
Sorry,

  if(wx.title == ""){...


0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9862948
Oh, and the window naming can be from at least three sources:
1.) Second parameter of window.open()
2.) Frame name
3.) Window name attribute assignment. Like this:
<script>
window.name = 'winXname';
</script>

0
 

Expert Comment

by:Chiller
ID: 9862964
what u could do is:

create a var for each window, i.e. winX, winY, winZ, set them to 0 by default.
then when you open a window, u set the window handle to the var.
in the opening function u simply check is its non 0 if so open then window if not dont :).

will post some code.

[code]
var winX=0, winY=0, winZ=0;

function openWin (which)
{
      if (which=="x")
            if (winX==0)
                  winX= window.open("location.html", "winX", "...");
            else
                  alert("Window already open !\n");
            
      if (which=="y")
            if (winY==0)
                  winY= window.open("location.html", "winY", "...");
            else
                  alert("Window already open !\n");


      if (which=="z")
            if (winZ==0)
                  winZ= window.open("location.html", "winZ", "...");
            else
                  alert("Window already open !\n");
}
[/code]
0
 

Author Comment

by:chrisnetonline
ID: 9863023
NetGroove,

Here's my function:

[code]
      function OpenIMWindow(bid,bname,action)
            {
            var wx = window.open("","im_"+bname,"width=50,height=50");
            if(wx.title=="")
                  {
                  wx.close();
                  var op_wid = "400";  
                  var op_heigh = "325";                
                  LeftPosition=(screen.width)?(screen.width-op_wid)/2:100;TopPosition=(screen.height)?(screen.height-op_heigh)/2:100;
                  var option = "top="+TopPosition+",left="+LeftPosition+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0, resizable=1,width="+op_wid+",height="+op_heigh;
                  var win = window.open("ims.php?id="+bid+"&bname="+bname, "im_"+bname, option);  
                  if (action == 0){win.focus();}
                  else if (action == 1){win.blur();}
                  }
            else
                  {
                  alert("Already Open!");
                  }
            }
[/code]

I never get the already open alert box :/
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:chrisnetonline
ID: 9863030
i'm trying to prevent the entire window from refreshing if window.opener detects a new message first
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 9864665
NG: What is wx.title ???
0
 
LVL 10

Accepted Solution

by:
NetGroove earned 0 total points
ID: 9865252
It was a typo.
Anyway was the window.title wrong recomandation.

Check please this:

<html>
<head>
<script>
function OpenIMWindow(bid,bname,action) {
  var wx = window.open("","im_"+bname,"width=100,height=100");
  if(wx.location.href=="about:blank") {
    wx.close();
    var op_wid = "400";  
    var op_heigh = "325";                
    LeftPosition=(screen.width)?(screen.width-op_wid)/2:100;TopPosition=(screen.height)?(screen.height-op_heigh)/2:100;
    var option = "top="+TopPosition+",left="+LeftPosition+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,

resizable=1,width="+op_wid+",height="+op_heigh;
    var win = window.open("ims.php?id="+bid+"&bname="+bname, "im_"+bname, option);  
  } else {
    alert("Already Open!");
    win = wx;
  }
  if (action == 0){
      win.focus();
  } else if (action == 1){
            win.blur();
          }
}
</script>
</head>
<body>
<a href="#" onClick="OpenIMWindow(100,'BidOne',0);return false">BidOne</a>
</body>
</html>



0
 

Author Comment

by:chrisnetonline
ID: 9869944
NetGroove... I get a message that says permission denied errors :/
0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9870147
All pages has to be in the same internet Domain.

You are not allowed to read attributes of foreign domain pages.

Tell us the url structure you are using.
And be aware that numeric (ip) and symbolic urls for same host are different domains.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

867 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

21 Experts available now in Live!

Get 1:1 Help Now