Solved

Check if named window exisits

Posted on 2003-12-02
10
1,819 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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
 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using javascript confirmation for a delete in mysql 5 31
jqury 17 30
alert(innerHTML); 8 15
Multiflying 2 Input Text On a Table 7 17
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

770 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