[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1829
  • Last Modified:

Check if named window exisits

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
chrisnetonline
Asked:
chrisnetonline
1 Solution
 
NetGrooveCommented:
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
 
NetGrooveCommented:
Sorry,

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


0
 
NetGrooveCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ChillerCommented:
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
 
chrisnetonlineAuthor Commented:
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
 
chrisnetonlineAuthor Commented:
i'm trying to prevent the entire window from refreshing if window.opener detects a new message first
0
 
Michel PlungjanIT ExpertCommented:
NG: What is wx.title ???
0
 
NetGrooveCommented:
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
 
chrisnetonlineAuthor Commented:
NetGroove... I get a message that says permission denied errors :/
0
 
NetGrooveCommented:
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

Technology Partners: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now